いくつかの記事を読んだ後、まだ混乱しています。StringBuilder の値を変更すると変更され、DateTime の値が変更されないのはなぜですか? 私が理解しているように、どちらも参照型です。
class Program
{
static void Main(string[] args)
{
DateTime myDt = DateTime.MinValue;
Change(myDt);
Console.WriteLine(myDt);
StringBuilder y = new StringBuilder();
y.Append("hello");
Foo(y);
Console.WriteLine(y);
String test = "hello";
Foo(test);
}
public static void Change(DateTime dt)
{
dt.AddDays(24);
//or dt=dt.AddDays(24);
}
static void Foo(StringBuilder x)
{
x.Append(" world");
}
static void Foo(String x)
{
x = x + " world";
}
}