C♯, C#相談室 Part36
■ このスレッドは過去ログ倉庫に格納されています
0683デフォルトの名無しさん
2007/01/08(月) 21:11:30class Program {
static void Main() {
String hellostr = "hello";
StringBuilder hellosb = new StringBuilder("hello");
world(hellostr, hellosb);
Console.WriteLine("String:{0},StringBuilder:{1}", hellostr, hellosb.ToString());
}
static void world(String str,StringBuilder sb) {
str = str + "world";
sb.Append("world");
}
}
このコードで"String:hello,StringBuilder:helloworld"と出力されるのは、
str = str + "world"においては"hello"とは違う
"helloworld"が入った別のインスタンスが生成され、
sb.Append("world")においては"hello"と同じインスタンスの中身が書き換わっているから
というのであっていますか?
■ このスレッドは過去ログ倉庫に格納されています