<<前のページへ
1: ArrayList list = new ArrayList(); // listという名前のArrayListを作成 2: list.Add("First Item"); //First Itemという文字列をArrayListに追加 3: list.Add("Second Item"); //Second Itemという文字列をArrayListに追加 4: string firstItem = (string)list[0]; //stringにキャストが必要 5: Console.WriteLine(firstItem);
1: string s1 = "文字列1"; 2: string s2 = "文字列2"; 3: string s3 = s1 + s2; //stringは+で繋げることができる
1: string s1 = "Hello"; 2: string s2 = "Hello"; 3: string s3 = "Bye"; 4: 5: if(s1 == s2) //s1とs2が等しいか比較 6: { 7: Console.WriteLine("s1はs2と等しい"); 8: } 9: else 10: { 11: Console.WriteLine("s1はs2と等しくない"); 12: } 13: 14: if(s2 == s3) //s2とs3が等しいか比較 15: { 16: Console.WriteLine("s2はs3と等しい"); 17: } 18: else 19: { 20: Console.WriteLine("s2はs3と等しくない"); 21: }
1: // 文字列2を作成2: string si = "2";3: 4: // int型に変換5: int i = System.Convert.ToInt32(si);
1: int i = 100;2: string s = i.ToString(); //string型に変換