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..
Frankly, it's not a real answer but a simple mention. If
Foo
was a struct so you can have something like this:Doesn't seem like it. From the documentation:
You can't override the default(T) keyword. It is always null for reference types and zero for value types.
More Information