zoukankan      html  css  js  c++  java
  • 学习笔记值类型和引用类型比较

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace TypeTest
    {
        class Program
        {
            static void Main(string[] args)
            {
                int[] ints = { 1, 2, 3, 4, 5 };//the array is refrenceType so after call SomeFunction the value will chnaged
                int i = 2;  //  int is valueType so  after call SomeFunction the value will not changed 
                TestObj obj = new TestObj(); //this is a object refrenceType after call SomeFunction the value will changed
                obj.age = 3;
    
                string str = "4"; //the string type is special refrenceType after call SomeFunction the value will not changed 
                Console.WriteLine(ints[0].ToString());
                Console.WriteLine(i.ToString());
                Console.WriteLine(obj.age.ToString());
                Console.WriteLine(str);
    
                SomeFunction(ints, ref i,obj,str);
    
                //after Call SomeFunction 
                Console.WriteLine(ints[0].ToString());
                Console.WriteLine(i.ToString());
                Console.WriteLine(obj.age.ToString());
                Console.WriteLine(str);
                Console.Read();
    
            }
            
            static void SomeFunction(int[] ints ,ref int i,TestObj obj,string str)
            {
                ints[0] = 100;
                i = 200;
                obj.age = 300;
                str = "400";
            }
        }
    
        class TestObj
        {
            public int  age = 1;
        }
    }
    

  • 相关阅读:
    MYSQL日志管理
    MYSQL权限管理
    MYSQL索引操作
    数据库基本操作
    MYSQL5.7的安装(yum、二进制、编译安装)
    记一次科来的培训--流量突发监测分析案例
    4、LNMP部署项目
    RIP
    OSPF(1)
    权限安全:sudo
  • 原文地址:https://www.cnblogs.com/liubaolongcool/p/2179245.html
Copyright © 2011-2022 走看看