Reputation: 41
In c# using .Net, if you create a class with an uninitialized field and without a constructor, then create an instance of the class with the new keyword, .Net sets the value of the field to the "default value". What exactly does that mean? Is there ever a situation where the value would be set to Null?
Upvotes: 4
Views: 552
Reputation: 20720
The default value is defined on a per-type basis. In general, any reference type will default to null
.
You can find a full list of default values based on the type in the documentation.
Furthermore, you can find out empirically by explicitly using the default
keyword and checking (e.g. in the debugger) what value was returned:
var x = default(string);
var y = default(int);
Upvotes: 5
Reputation: 6610
Like Johnny mentioned in the comments, this table lists the default values for .NET types. The default value of a reference-type field is null
.
Upvotes: 6