I have previously introduced the default value of C #3.0 {Get; set;}. This article is based on it and adds some content.
. NET Framework 3.5 uses C #3.0, and C #3.0 has some new language features, one of which is quick attributes.
Previous statement:
Private int _ id = 0;
Public int ID
{
Get
{
Return _ id;
}
Set
{
_ Id = value;
}
}
C #3.0 can be abbreviated as follows:
Public int ID {Get; set ;}
C #3.0 {Get; set;} Default Value
This means the default value of {Get; set;} does not exist. We cannot manually specify the default value because the private self-segment does not exist. What is the default value of the system?
- For int type, the default value is 0;
- For Int? Type. The default value is null;
- For the bool type, the default value is false;
- For bool? Type. The default value is null;
- For the string type, the default value is null;
- For string? Type, haha. If this method is not used, errors may occur;
- For the datetime type, the default value is 0001-01-01 00:00:00;
- For datetime? Type. The default value is null;
- For the enum type, the default value is 0. If there is no Enum item of 0, it is still 0. For more information, see C # enumeration (Enum );
- For Enum? Type. The default value is null;
- For the class type, the default value is the reference of an uninstantiated object;
- For class? Type.
About type addition ?, Indicates that the value of this type can be null. For example, if int does not have a null value, add Int? It can be null.