ソースの先頭行にusing ~と記述する。
記述方法
Streamクラスを用いて、サーバーからファイルを読み出す場合
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using System.Net; using System.IO; // ← ここに記述 namespace CardReader { class Program { static void Main(string[] args) { WebClient wc = new WebClient(); using (Stream st = wc.OpenRead("http://study-csharp.blogspot.jp/")) { using (StreamReader sr = new StreamReader(st, Encoding.UTF8)) { string html = sr.ReadToEnd(); Console.Write(html); } } } } }
usingとは
「using System.IO;」におけるSystem.IOは名前空間(namespase)を指します。この名前空間以下に定義されている関数にパスを通しますという意味。 JAVAでいうimport文。
Streamクラスを使用したい場合は、「System.IO」以下に定義されているクラスのため、using System.IOと記述します。 using System.IO.Streamと記述してはいけません。