Can object constructor return a null?

前端 未结 5 1016
伪装坚强ぢ
伪装坚强ぢ 2020-12-30 19:32

We have taken over some .NET 1.1 Windows Service code that spawns threads to read messages off a queue (SeeBeyond eGate JMS queue, but that is not important) and in turn spa

5条回答
  •  春和景丽
    2020-12-30 19:57

    NO! that null check is redundant. Lot of C++ devs who moved to C# have this habit of a null check and I guess it is the same here.

    The only thing is you should check the documentation to see if the constructor can throw any exception. In your case refer to http://msdn.microsoft.com/en-us/library/xx3ezzs2.aspx and as mentioned the constructor will always return a valid obj.

提交回复
热议问题