C#に限らず、プログラミングをしていて、外部ファイルを開いたりコネクションを開いておいたりすることは多い。 そういった場合、後始末を忘れると、例えばファイルを開きっぱなしにしたりと、あちゃちゃ〜なコトになってしまう。 しかし、我々も人間。後始末をつい忘れてしまうこともある。C#でいうと、対象のオブジェクトのDispose()を呼び忘れたということだけれど、さすが至れり尽くせりのC#、そんなヒューマンエラーを防ぐ仕組み = usingステートメントを用意している。 後始末のためのインターフェース usingステートメントの有り難みを紹介する前に、.Netが用意している後始末のためのインターフェースをおさらいしておこう。 前述の外部ファイルやアンマネージドリソースを開放するため、.NetはIDisposableというインターフェースを用意している。その内容はこちら。namespace Syst