zoukankan      html  css  js  c++  java
  • 特殊引用类型(string)

     private string FuncWithParameters(int param1, String param2, List<string> param3)
            {
                // 我们在这里改变参数值
                param1 = 100;
                param2 = "hello";
                param3.Add("sfs");
                return "thank you for reading me";
            }
            public void Test()
            {
                int intValue = 200;
                String strParam = "hi";
                List<string> list = new List<string>();
                list.Add("Item1");
    
                FuncWithParameters(intValue, strParam, list);
                Console.WriteLine("param1: " + intValue);
                Console.WriteLine("param2: " + strParam);
                Console.WriteLine("list count: " + list.Count);
    
                Console.ReadLine();
            }

    自己先心里猜猜param1、param2、list count是什么值, 按照逻辑思维想既然是引用类型那么输出结果应该为:param1:200、param2:"hello"、list count :2;

    实际上并不是我们逻辑思维的那样,因为string类型比较特殊(MSDN上这样解释:字符串对象是不可变的,即它们一旦创建就无法更改。对字符串进行操作的方法实际上返回的是新的字符串对象。) ,也可以看下其他园子里的详细解释:C# string 特殊的引用类型

    正确的结果为:param1:200、param2:"hi"、list count :2。

    广告插播欢迎同行加入企鹅群:662685831

  • 相关阅读:
    mmap和MappedByteBuffer
    Linux命令之TOP
    Linux命令之ss
    MySql Cluster
    HttpClient配置
    注释驱动的 Spring cache 缓存介绍
    Spring AOP 实现原理与 CGLIB 应用
    AspectJ本质剖析
    B树
    imagick-3.1.0RC2 安装错误
  • 原文地址:https://www.cnblogs.com/yokoo/p/7246553.html
Copyright © 2011-2022 走看看