Do I have to Dispose the SQLiteCommand objects?

后端 未结 4 1911
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-18 08:33

How do I treat the SQLiteCommand object, do I have to call Dispose() after ExecuteScalar, ExecuteNonQuery

4条回答
  •  既然无缘
    2021-01-18 08:57

    The using statement will call Dispose on an object even if an exception occurs that bypasses the code that calls Close(). This way you don't have to write a try/finally block just to close the readers or the connection. You also avoid this 1-in-100 case where you forget to write the proper finally block.

    Such 1-in-100 cases have a tendency to occur much more frequently than one would think

提交回复
热议问题