約束屬性錯(cuò)誤
?private int age;//年齡
? ? ? ? public int Age
? ? ? ? {
? ? ? ? ? ? get { return age; }
? ? ? ? ? ? set { if (age>=3&&age <=7)? age = value;}
? ? ? ? }
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? Child XioaMing = new Child();
? ? ? ? ? ? XioaMing.Name = "李曉明";
? ? ? ? ? ? XioaMing.Sex = "男";
? ? ? ? ? ? XioaMing.Age = 6;
? ? ? ? ? ? XioaMing.Height = 125;
? ? ? ? ? ? Console.WriteLine("我叫"+ XioaMing .Name +",我今年"+ XioaMing.Age +"歲。"+"身高"+XioaMing.Height+"cm.");
? ? ? ? ? ? XioaMing.PlayBall();
? ? ? ? }
? ? }
}? ? ? ? ?為什么輸出年齡為0歲
2019-09-12
if語(yǔ)句對(duì)value不是age
2019-08-27
是不是set{}里的代碼要換行???