The post Declaring variables as nullable in c# describes how nullable value types can be declared used in C#.
.NET Framework also provides the ?? operator, called the null-coalescing operator, and its primary use is to define a default value for a nullable value types as well as reference types. It returns the left-hand operand if it is not null; otherwise it returns the right operand.
As an example, if the following code is run, the intValue will be 1, since nullInt is null.
.NET Framework also provides the ?? operator, called the null-coalescing operator, and its primary use is to define a default value for a nullable value types as well as reference types. It returns the left-hand operand if it is not null; otherwise it returns the right operand.
As an example, if the following code is run, the intValue will be 1, since nullInt is null.
Nullable<int> nullInt = null;
int intValue = nullInt ?? 1;
1 comments:
Hello, I like this blog.
Sorry not write more, but my English is not good.
A hug from Portugal
Post a Comment