zoukankan      html  css  js  c++  java
  • 引用类型传递参数的特殊情况(string)

        struct Patient
        {
            public string status;
        }
        class Person
        {
            public string life;
        }
        class Program
        {
            static void Main(string[] args)
            {
                Patient ps = new Patient();
                ps.status = "我生病了";
                SeeDoctor(ps.status);
                Console.WriteLine("结构类型patient的status:{0}", ps.status);
                //ps.status的结果为"我生病了"
    
                Person pc = new Person();
                pc.life = "生病了";
                SeeDoctor(pc.life);
                Console.WriteLine("类类型Person的life:{0}", pc.life);
                //pc.life的结果为"我生病了".
                Console.ReadKey();
            }
            static void SeeDoctor(string temp)
            {
                temp = "病好了";
            }
        }

     (图中: 线程栈误写成了"线型栈",另外temp变量是在SeeDoctor方法的线程栈上,而ps 和pc 两个变量是在Main方法的线程栈上.)

    图解:

      

    图解:

    struct Patient
        {
            public string status;
        }
        class Person
        {
            public string life;
        }
        class Program
        {
            static void Main(string[] args)
            {
                Patient ps = new Patient();
                ps.status = "我生病了";
                SeeDoctor( out ps.status);
                Console.WriteLine("结构类型patient的status:{0}", ps.status);
                //ps.status的结果为"病好了"
    
                Person pc = new Person();
                pc.life = "生病了";
                SeeDoctor(out pc.life) ;
                Console.WriteLine("类类型Person的life:{0}", pc.life);
                //pc.life的结果为"病好了".
                Console.ReadKey();
            }
            static void SeeDoctor( out string temp)
            {
                temp = "病好了";
            }
        }

     图解(此时,结构与结构基本一致):

    我叫小小菜,想要成为一棵大大包心菜.
  • 相关阅读:
    JS中location.search和setTimeout()和 setInterval()
    javascript的AJAX和Serialize(),解码
    php的变量和基本语法
    isnan
    Urllib 库的基础和实用(2)
    urllib 库的基础和实用(1)
    python获取网页精准爬取数据
    eclipse配置
    搭建JAVA WEB开发环境(tomcat)
    JDK环境变量配置
  • 原文地址:https://www.cnblogs.com/tobecabbage/p/3454706.html
Copyright © 2011-2022 走看看