value其實就是C#類里邊的屬性,比如,我們有個類叫Student,cs,里邊有int類型名為“ID”的屬性,我們在構造函數里接收傳入的值然后為這個屬性賦值,然后實例化類,傳入一個1,這是value就是1;如下:
public class Student
{
public Student(int id)
{
this.Id = id;
}
public int Id
{
get { return Id; }
set
{
if (value == 1)
{
Console.WriteLine("hello world!");
}
}
}
}
然后實例化類,傳入參數值,如下:
Student student = new Student(1); Console.ReadKey();
這個時候就會輸出:hello world!
