using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 值传递和引用传递
{
class Program
{
/// <summary>
/// 值类型:int double char decimal bool enum struct
/// 引用类型:string 数组 自定义类 集合 object 接口
/// 值传递只传递值.对象传递在帐中不一样.堆中一样;
///
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
person p1 = new person();
person p2 = new person();
p1.Name = "aaa";
p2 = p1;
p2.Name = "bbb";//p1.p2.name=bbb;
Console.WriteLine(p1.Name);//输出BBB
Console.WriteLine(p2.Name);//输出BBB
Console.ReadKey();
}
}
public class person
{
private string _name;
//封装字段快捷键:ctrl+r,e
public string Name
{
get { return _name; }
set { _name = value; }
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 值传递和引用传递
{
class Program
{
/// <summary>
/// 值类型:int double char decimal bool enum struct
/// 引用类型:string 数组 自定义类 集合 object 接口
/// 值传递只传递值.对象传递在帐中不一样.堆中一样;
///
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
person p1 = new person();
person p2 = new person();
p1.Name = "aaa";
p2 = p1;
p2.Name = "bbb";//p1.p2.name=bbb;
Console.WriteLine(p1.Name);//输出BBB
Console.WriteLine(p2.Name);//输出BBB
Console.ReadKey();
}
}
public class person
{
private string _name;
//封装字段快捷键:ctrl+r,e
public string Name
{
get { return _name; }
set { _name = value; }
}
}
}