C# -- value是什么意思?


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!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM