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..
* Structs have statically-dispatched methods and properties; there's no ability to override.
Default represents default value of T parameter in generics intructions. In several cases, the default keyword is an absolute unknown and we think it's unnecessary or its functionality is null. There are many development moments with the generics classes where the default keyword can be useful.
You can't override the default(T) keyword. It is always null for reference types and zero for value types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With