Tech Off Post

Single Post Permalink

View Thread: null + null = ?
  • User profile image
    footballism

    Londoner wrote:
    Here is another one for you:

    class Class1
    {
          public int c = true;  // <---- It compiles!!
           
          public Class1(): this(0) {}
          public Class1(int i): this() {} 
          [STAThread]
          static void Main(string[] args)
          {
                 
          }
    }

    yes,this class(Class1) can be compiled,but why the following cannot be compiled.

    class Class1
    {
          public int c = true;  // <---- It compiles!!
           
          public Class1(int i){} 
          [STAThread]
          static void Main(string[] args)
          {      
          }
    }


    I am pretty confused when the C# compiler issues a compile-time error
    saying that there is no explicit conversion from boolean type to int32 type.
    I just wanna simply ask why?