namespace ConsoleApplication1{spa
class Program{rem
static void Main(string [] args ){get
ReferenceAndValue.Demonstration(); //調用ReferenceAndValue中的Demonstration方法string
}
}it
public class stamp{ //定義一個類
public string Name{get; set;} //定義引用類型io
public int Age{get;set;} //定義值類型
}
public static class ReferenceAndValue{ //定義一個靜態類
public static void Demonstration(){ //定義一個靜態方法class
stamp Stamp_1=new stamp{Name=''Premiere",Age=25} //實例化
stamp Stamp_2=new stamp{Name=''Again",Age=47} //實例化
int Age=Stamp_1.Age; //獲取值類型Age的值
Stamp_1.Age=22; //修改值類型的值
stamp guru=Stamp_2; //獲取Stamp_2中的值
Stamp_2.Name="Again Amend";//修改引用的Name值
Console.writeLine("Stamp_1's age:{0}"Stamp_1.Age);//顯示Stamp_1中的Age值
Console.writeLine("age's value:{0}",age);//顯示age的值
Console.writeLine("Stamp_2's name:{0}"Stamp_2.Name)//顯示Stamp_2中的Name的值;
Console.writeLine("guru's name:{0}",guru.Name);引用
}
}
}方法