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

前端 未结 5 810
花落未央
花落未央 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:18

    You will not get null reference exception as per my experience. It will be simply ignored.

提交回复
热议问题