Hi,
The default value expression produces the default value of a type, the default() need a type name or a type parameter in ().
For example:
Console.WriteLine(default(int)); // output: 0
Console.WriteLine(default(object) is null); // output: True
void DisplayDefaultOf<T>()
{
var val = default(T);
Console.WriteLine($"Default value of {typeof(T)} is {(val == null ? "null" : val.ToString())}.");
}
DisplayDefaultOf<int?>();
DisplayDefaultOf<System.Numerics.Complex>();
DisplayDefaultOf<System.Collections.Generic.List<int>>();
// Output:
// Default value of System.Nullable`1[System.Int32] is null.
// Default value of System.Numerics.Complex is (0, 0).
// Default value of System.Collections.Generic.List`1[System.Int32] is null.
Because c.DefaultTop is a property value, so if you used like default(c.DefaultTop), The compiler displayed an error :"'c' is a variable but is used like a type";
If the c.DefaultTop is a bool type property, you can use default as below:
bool x = default(bool);
For more ,please refer:
default value expressions (C# reference)
If right, please Accept.
Enjoy programming!!!