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;
        }
    }
    

  • 相关阅读:
    linux设置永久别名
    网站架构
    c#: 判断Firefox是否安装
    似是故人来
    Python: re.sub()第二个参数
    Python: AES加密与解密
    c#: Noto Sans字体如何支持韩文
    Inno Setup安装程序单例运行
    朵朵的二维码
    Python: 浅淡Python中的属性(property)
  • 原文地址:https://www.cnblogs.com/liubaolongcool/p/2179245.html
Copyright © 2011-2022 走看看