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

  • 相关阅读:
    查看 lib 库信息
    评委打分(C++ 容器综合练习)
    二阶段12.16
    对搜狗输入法的使用心得
    二阶段12.14
    二阶段12.13
    二阶段12.12
    典型用户描述
    水王(课堂练习)
    一阶段11.21
  • 原文地址:https://www.cnblogs.com/liubaolongcool/p/2179245.html
Copyright © 2011-2022 走看看