Why is there no RAII in .NET?

后端 未结 7 934
生来不讨喜
生来不讨喜 2020-12-04 14:59

Being primarily a C++ developer the absence of RAII (Resource Acquisition Is Initialization) in Java and .NET has always bothered me. The fact that the onus of cleaning up i

7条回答
  •  天命终不由人
    2020-12-04 15:42

    There's some similar threads if you search for them but basicly what it boils down to is that if you want to RAII on .NET simply implement an IDisposable type and use the "using" statement to get deterministic Disposal. That way many of the same ideoms can be implemented and used in only a slightly more wordy manner.

提交回复
热议问题