When do we need to call Dispose() in dot net c#?

前端 未结 4 1922
眼角桃花
眼角桃花 2020-12-10 05:58

Do I need to dispose a sqldatareader after it is created?

SqlDataReader reader;
---
---
---
reader.Close();
reader.Dispose();
4条回答
  •  天涯浪人
    2020-12-10 06:16

    Object which are Disposable can be best used (if possible) in a using block. At the end of the using block, the object is automatically disposed.

    Because of memory management it is always advised do dispose your objects if you don't need them anymore.

    Here's some stuff to read from the MSDN.

提交回复
热议问题