get,set and value keyword in c#.net

前端 未结 3 1922
夕颜
夕颜 2020-12-29 13:14

What is value keyword here and how is it assigning the value to _num? I\'m pretty confused, please give the description for the following code.

3条回答
  •  离开以前
    2020-12-29 13:58

    Properties are the way you can READ, WRITE or COMPUTE values of a private field or class variable. The set or setter inside a property is used when the code assigns a value into the private field or (class) variable. The value keyword means simply "the thing that is being assigned".

        public class StaffMember 
        { 
            private int ageValue; 
            public int Age 
                { 
                     set 
                         { 
                             if ( (value > 0) && (value < 120) ) 
                                 { this.ageValue = value; } 
                         } 
                     get { 
                          return this.ageValue; 
                         } 
                } 
        }
    //Rob Miles - C# Programming Yellow Book
    

提交回复
热议问题