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

  • 相关阅读:
    html-Notes3
    html-Notes2 表单
    html 笔记
    网页设计常用色彩搭配表
    css
    html-Notes
    C# 输入字符串,每3个截取一次,形成一个数组
    提高情商的好书推荐 (程序猿不仅要智商也要情商)
    PHP 学习笔记---基本语法
    php学习笔记之字符串处理
  • 原文地址:https://www.cnblogs.com/liubaolongcool/p/2179245.html
Copyright © 2011-2022 走看看