this == null inside .NET instance method - why is that possible?

后端 未结 5 852
别那么骄傲
别那么骄傲 2020-12-14 15:22

I\'ve always thought that it\'s impossible for this to be null inside instance method body. Following simple program demonstrates that it is possible. Is this s

5条回答
  •  眼角桃花
    2020-12-14 15:33

    this is a readonly reference in C# classes. Accordingly and as expected this can be used like any other references (in read only mode) ...

    this == null // readonly - possible
    this = new this() // write - not possible
    

提交回复
热议问题