--------------------- ASP.Net+Android+IOS开发.Net培训期待与您交流! ----------------------
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 = "病好了";
}
}
图解(此时,结构与结构基本一致):