C# can be empty type: in -depth understanding of the role of the question mark
Question mark is usually used in conditional sentences, but in C#, it also plays a vital role in indicating the type of empty types.
In C#, the available type (eg,
) using the question mark suffix is a special data type, which can not only represent the valid value of its basic value type, but also indicate the empty value. This function is particularly useful when processing may contain databases or other data sources that are missing or not assigned.
int? myVariable
When using the empty type, you can use the
attribute to access the actual value. If is fake, the variable is not valid and is considered to be empty. HasValue
HasValue
For example, consider the following code fragment: Value
HasValue
attribute to check the empty value.
<code class="language-csharp">public int? myProperty { get; set; }</code>
The above is the detailed content of What is the Purpose of the Question Mark in C# Nullable Types?. For more information, please follow other related articles on the PHP Chinese website!