C#语句先后顺序对程序的结果有影响吗

2019-12-26 14:15:29丽君
有朋友问我,C#中C#语句先后顺序影响程序的结果吗?告诉大家,答案是肯定的,绝对影响程序的结果,所以在程序中一定要注意C#语句的顺序    

下面通过一段代码给大家解析C#语句的顺序不同所执行的结果不一样。
 

  1. using System;   using System.Collections.Generic; 
  2.  using System.Linq;   using System.Text; 
  3.  namespace Test   { 
  4.   /// <summary>    /// 自定义类,封装加数和被加数属性 
  5.   /// </summary>    class MyClass 
  6.   {     private int x = ;      //定义int型变量,作为加数 
  7.    private int y = ;      //定义int型变量,作为被加数     /// <summary> 
  8.    /// 加数     /// </summary> 
  9.    public int X     { 
  10.     get      { 
  11.      return x;      } 
  12.     set      { 
  13.      x = value;      } 
  14.    }     /// <summary> 
  15.    /// 被加数     /// </summary> 
  16.    public int Y     { 
  17.     get      { 
  18.      return y;      } 
  19.     set      { 
  20.      y = value;      } 
  21.    }     /// <summary> 
  22.    /// 求和     /// </summary> 
  23.    /// <returns>加法运算和</returns>     public int Add()