我试图为我的结构体设置默认值。例如,Int的默认值为0,DateTime的默认值为1/1/0001 12:00:00 AM。众所周知,在结构体中无法定义无参数构造函数。
struct Test
{
int num;
string str;
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine(default(Test)); // shows namespace and name of struct test.Test
Console.WriteLine(new Test()); // same
Console.ReadKey(true);
}
}
如何为结构体设置默认值?