I am reading an article about the MVVP Pattern and how to implement it with WPF. In the source code there are multiple lines where I cannot figure out what the question marks in it stand for.
private DateTime? _value;
What does the ?
mean in the definition? I tried to find it in the help from VS but failed.
Question marks on TypeScript variable are used to mark that variable as an optional variable.
With C# 8, the placing of a question mark character on ANY type will now be treated as an indicator of weather a variable may or may not be null, not in terms of preventing compilation outright, but in terms of how the compiler responds and warns about it.
It is a shorthand for Nullable<int> . Nullable<T> is used to allow a value type to be set to null .
Question mark means "optional". So it's a shorthand for "parameter: type | undefined = undefined"..
It's a nullable value. Structs, by default, cannot be nullable, they must have a value, so in C# 2.0, the Nullable<T>
type was introduced to the .NET Framework.
C# implements the Nullable<T>
type with a piece of syntactic sugar, which places a question mark after the type name, thus making the previously non-nullable type, nullable.
That means the type is Nullable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With