本帖最后由 苟于伟 于 2013-5-17 11:49 编辑
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- Pr r1 = new Pr();
- r1.Eat(5);
- Console.WriteLine(r1.FullLevel);
- Console.ReadKey();
- }
- class Pr {
- public int FullLevel { get; set;
- public void Eat(int foodCount)
- {
- if (FullLevel > 100)
- {
- return;
- }
- FullLevel = FullLevel + foodCount;//按理说FullLevel的应该为10
- }
- }
- }
- }
复制代码 当Eat将5这个值传进来时,FullLevel为5 , foodCount也为5,可为什么 FullLevel + foodCount得到的新值还是5呢?应该是10才对呀!
|