xxxxxxxxxx
int x = int.Parse(onsole.ReadLine());
if ( x >= 100 )
Console.WriteLine("True");
else
Console.WriteLine("False");
xxxxxxxxxx
int? nullableInt = null;
float? nullableFloat = 3.14f;
if (nullableInt.HasValue)
{
Console.WriteLine("Nullable int: " + nullableInt.Value);
}
else
{
Console.WriteLine("Nullable int is null");
}
if (nullableFloat.HasValue)
{
Console.WriteLine("Nullable float: " + nullableFloat.Value);
}
else
{
Console.WriteLine("Nullable float is null");
}
xxxxxxxxxx
//Nullable value types
int? nullableInt = null;
float? nullableFloat = 3.14f;
//Using nullable types
string? nullableString = "Nullable string";
nullableString = null;
//Checking if a nullable type has value
if (nullableInt.HasValue)
{
// Value is not null, perform operations
int result = nullableInt.Value + 10;
}
else
{
// Value is null, handle accordingly
}
//Null-Coalescing Operator
int nonNullableValue = nullableInt ?? 0;