2013-02-07から1日間の記事一覧

リストクラスも簡潔に

C#

リストで配列のようなことをやると手間です。 配列の場合 int[] a = { 1, 2, 3, 4, 5}; for(int i=0; i < a.Lenght; ++i) Console.WriteLine(a[i]); リストの場合 List list = new List(); list.Add(5); list.Add(4); list.Add(3); list.Add(2); list.Add(1)…

定数も変換可能?

C#

public static void Main(string[] args) { string s = 1.ToString(); Console.WriteLine(s); } よくわかりません。

拡張メソッド

C#

静的クラス中に、第1引数にthisキーワードを修飾子として付けたstaticメソッド static class StringExtensions { public static string AddTest(this string s) { s = "ok"; return s; } } string s = "This is a Test String."; string s1 = StringExtensi…

例外 try catch throw

C#

static void Main(string args) { CMain main = new CMain(); int a = new int[10]; try { Console.WriteLine(a[11]); } catch (ArgumentOutOfRangeException) { //エラー分投げ 例外発生 throw; } 例外処理の中で、また例外処理をしたい場合に使用するみた…