Class User { privateint hp = 20; //給予初始值 publicint HP { get { return hp;} //讀取時回傳hp set { if(value < 0)//當有傳入值時判斷 { hp = 0;//小於0 hp就等於0 } else{ hp = value;//不小於0 hp就等於傳入的值 } } } }
privatevoidbtn1_Click(object sender, EventArgs e) { User user = new User();