为什么这是有效的 public struct MyStruct{ public MyStruct(double value) { myField = value; } private double myField; public double MyProperty { get { return myField; } set { myField = value; } }} 而事实并非如此 public struct M
public struct MyStruct { public MyStruct(double value) { myField = value; } private double myField; public double MyProperty { get { return myField; } set { myField = value; } } }
而事实并非如此
public struct MyStruct { public MyStruct(double value) { MyProperty = value; } public double MyProperty { get; set; } }你需要这个语法:
public struct MyStruct { public MyStruct(double value) : this() { MyProperty = value; } public double MyProperty { get; set; } }
我从following SO帖子那里得到了这些信息.