//像 int,char,datetime,bool等类型属于值类型(ValueType),赋值的时候是传递拷贝。
//普通的对象则是引用类型,赋值的时候是传递引用。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Lesson2
{
class Program
{
static void Main(string[] args)
{
int i = 10;
// 把i的值拷贝给j,所以j的值是10
int j = i;
Console.WriteLine(j);
//声明一个 Person类型的 引用 p1,指向 Person(10) 对象.
Person p1 = new Person(10);
//声明一个 Person类型的 引用 p2,指向 p1。
Person p2 = p1;
//p1指向的对象的属性 Age加1
p1.Age++;
//输出p2 指向的对象的属性 Age。因为p2 指向 p1 ,p1指向的对象的Age为11,所以输出11.
Console.WriteLine(p2.Age);
Console.ReadKey();
}
}
class Person
{
public int Age { set; get; }
public Person(int age)
{
this.Age = age;
}
}
}