c# -- using 문 ( using Statement )
c# -- using 문 ( using Statement )
테스트 환경 : vistual studio 2013, windows 7 64bit
참고 : C#을 이용한 윈도우 폼 프로그래밍, 초판 p.170~172
https://msdn.microsoft.com/ko-kr/library/yh598w02.aspx --> using 문
https://msdn.microsoft.com/ko-kr/library/system.idisposable.aspx
http://www.completecsharptutorial.com/basic/using.php ---> IDisposable Interface 구현 예
http://hoons.net/Board/cshaptip/Content/27776
http://stackoverflow.com/questions/9396064/using-statement-with-multiple-variables --> 2중 using 문 사용.
https://riptutorial.com/csharp/example/299/multiple-using-statements-with-one-block --> 다중 using 문 사용법.
* file handle, db 연결, dc 같은 unmanaged resources 나 class 는 반드시 IDisposable Interface 를 구현해야 한다.
* IDisposable Interface 구현한 객체를 사용하고 난후에는 반드시 IDisposable Interface 의 Dispose() 메소드를 호출해야한다.
==> 이를위해 try - finally 블록 사용.
==> 이는 using 문 으로 바꿀수 있다.
( 내부적으로 try block 을 포함하고 있으며, using scope 벗어나는 순간 자동으로 Dispose() 메소드 호출한다.)
; 즉, exception 발생하더라도 Dispose() 호출을 보장한다.
-- using 문이 간결하고 가독성 좋음...
결론 : IDisposable Interface 구현한 객체는 using 문 사용하자!!!!