C Sharp

C#

static コンストラクタ

staticなコンストラクタは、そのクラスのインスタンスが最初に作成されるよりも前に実行される
厳密なタイミングは不定
public class SomeClass{
    static SomeClass(){
        //staticコンストラクタの処理
    }
} 


多次元配列のサイズ

Array.GetLength(int)は引数に指定した次元の要素数を返す
int[,] arr = new int[3,5];
int a =  arr.GetLength(0); //3
int b = arr.GetLength(1); //5
 

文字列(string)をintに変換

int.Parseを使う
string str = "123";
int.Parse(str);
 

Webページの読み込み

WebRequest、WebResponseから派生したHttpWebRequest、HttpWebResponseクラスを使う
WebRequest.Create()に"http://"から始まるURIを渡すとHttpWebResponseオブジェクトが返されるのでキャストして使う

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.yahoo.co.jp");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.ASCII);
 
最終更新:2011年01月22日 23:37
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。