字符串的引用类型当做值类型来处理

来源:互联网 发布:犀牛软件模型立面 编辑:程序博客网 时间:2024/06/06 01:44
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 字符串引用
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = "abc";
            ChangeStr( str);
            Console.WriteLine(str);
            Console.ReadKey();
        }
        public  static void ChangeStr(  string  a)
        {
            a = "123";
        }
    }

}

//输出结果还是abc,str的值并没发生改变

 这里我们要特别注意字符串类型的变量是引用类型,但是他在使用的时候在某些特定的情况下显示的是值类型的特性。

简单的说,如果遇到函数参数传递,你就把字符串类型的当做值类型的使用.




0 0
原创粉丝点击