Will Dispose() be called in a using statement with a null object?

前端 未结 5 809
花落未央
花落未央 2020-12-04 18:37

Is it safe to use the using statement on a (potentially) null object?
Consider the following example:

class Test {
    IDisposable GetObject         


        
5条回答
  •  臣服心动
    2020-12-04 19:06

    Yes, before Disposing the reference will be null-checked. You can examine yourself by viewing your code in Reflector.

提交回复
热议问题