How to override default(T) in C#? [duplicate]
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Howto change what Default(T) returns in C# print(default(int) == 0) //true Similarly if I have a custom object, its default value will be null. print(default(Foo) == null) //true Can I have a custom value for default(Foo) and not null? For example, something like this: public static override Foo default() { return new Foo(); } This wont compile. Thanks.. 回答1: You can't override the default(T) keyword. It is