直接来一段测试代码

 class value_ref_type
    {
        public static void DEMO1()
        {
            double[] location = new double[2] { 1.256589, 489789 };
            double[] location_new;
            string str_1, str_2;

            Console.Out.WriteLine("ori location: x,{0};y{1}", location[0], location[1]);
            location_new = location;
            location[0] = 1.11111111111;
            str_1 = "weng";
            str_2 = str_1;
            str_1 = "jun";
            ChangeStrValue(str_2);

            Console.Out.WriteLine("out location: x,{0};y{1}", location_new[0], location_new[1]);
            Console.Out.WriteLine("out str ref: str1,{0};str2,{1}", str_1, str_2);
        }

        public static void ChangeStrValue(string str)
        {
            str = "tom";
        }
    }

C#中有关数组和string引用类型或值类型的判断_默认值

结论:

(1)数组是引用类型的;

(2)string对象声明后尚未赋值的,string对象的默认值为null;

(3)string对象尚未赋值时虽然为null,但其和值类型的特性更为契合;在函数调用过程操作中,如果想在被调函数中修改主调函数的string值,最好参数加ref修饰。

 

你们的评论、反馈,及对你们有所用,是我整理材料和博文写作的最大的鼓励和唯一动力。欢迎讨论和关注!
没有整理与归纳的知识,一文不值!高度概括与梳理的知识,才是自己真正的知识与技能。 永远不要让自己的自由、好奇、充满创造力的想法被现实的框架所束缚,让创造力自由成长吧! 多花时间,关心他(她)人,正如别人所关心你的。理想的腾飞与实现,没有别人的支持与帮助,是万万不能的。