Tom,
See inline:
I didn't say it was wrong, just not quite right. Just because the
compiler allows it doesn't mean it's right.
I'm not going to get into what is absolutely right or wrong. The fact
of the matter is that the C# compiler allows the operation, and the current
C# compiler is the most accurate enforcer (even if it is by virtue of being
the only one, or one of a few) of the C# language specification, which I
consider, when it comes to matters of C#, to be absolutely right.
> Also, the default for a value type is if the default parameterless
constructor was called on it, which zeroes out the structure (so
references are null, other structure fields are zeroed out). It's not
just numeric types.
Didn't mean to infer that it was, sorry you misunderstood.
On the next interview you can ask, explain the difference between the
following:
int x = default(int);
int x = 0;
int x = new int();
There was nothing I misunderstood. You had narrowed your definition of
what default does by too much. You stated:
In that case, default will return a null if it is a reference type, and 0 if
it is a numeric value type.
However, what about this type:
public struct MyStruct
{
public string MyString;
}
The above type is not a numeric value type, and there is no defined
behavior according to your original statement (which you subsequently try to
reinforce by being unjustifiably snarky, IMO). My statement, however,
covers the structure above (and ones like it) which are not necessarily
numeric in nature.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com