zoukankan      html  css  js  c++  java
  • C#中有关数组和string引用类型或值类型的判断

    直接来一段测试代码

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

    结论:

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

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

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

  • 相关阅读:
    Amazon Route 53
    监控应用程序负载均衡器ALB
    DynamoDB 流
    DynamoDB 中的限制
    Amazon SNS 消息属性
    关于基于 SAML 2.0 的联合身份验证
    Amazon EBS 性能提示
    Laravel5.1注册中间件的三种场景
    编译LNMP环境
    傻瓜式搭建LAMP环境
  • 原文地址:https://www.cnblogs.com/arxive/p/9034932.html
Copyright © 2011-2022 走看看