Nullable Type in C#
What is nullable type in C# and how to assign a value on it.
value type cannot be assigned a null value. For example, int i = null will give you a compile time error.
C# 2.0 introduced nullable types that allow you to assign null to value type variables.
You can use the '?' operator to shorthand the syntax e.g. int?, long?
int? i = null;
double? D = null;
?? Oprator
Use the '??' operator to assign a nullable type to a non-nullable type.
int? i = null;
int j = i ?? 0;
Console.WriteLine(j);
Null is considered to be less than any value. So comparison operators won't work against null.
Видео Nullable Type in C# канала OrBit of the CodinG
value type cannot be assigned a null value. For example, int i = null will give you a compile time error.
C# 2.0 introduced nullable types that allow you to assign null to value type variables.
You can use the '?' operator to shorthand the syntax e.g. int?, long?
int? i = null;
double? D = null;
?? Oprator
Use the '??' operator to assign a nullable type to a non-nullable type.
int? i = null;
int j = i ?? 0;
Console.WriteLine(j);
Null is considered to be less than any value. So comparison operators won't work against null.
Видео Nullable Type in C# канала OrBit of the CodinG
Комментарии отсутствуют
Информация о видео
26 марта 2023 г. 16:05:46
00:03:55
Другие видео канала