Tech Off Post

Single Post Permalink

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

    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)
          {
                 
          }
    }



    It compiles because there is no syntax error, and the compiler can make code for it, just as it does for this:

    public void First()
    {
      this.Second();
    }

    public void Second()
    {
      this.First();
    }

    It's no different. The compiler isn't fooled, it is doing exactly what you told it to do.