Skip to content

Instantly share code, notes, and snippets.

@anilkay
Created January 5, 2022 08:20
Show Gist options
  • Select an option

  • Save anilkay/e109031dbf68895816b5b45fc19c7ecc to your computer and use it in GitHub Desktop.

Select an option

Save anilkay/e109031dbf68895816b5b45fc19c7ecc to your computer and use it in GitHub Desktop.
// See https://aka.ms/new-console-template for more information
int ?nullable = null;
//var a = (int)(nullable + nullable); NUllable object must have a value
nullable = 44;
var a = (int)(nullable + nullable); //Work fine but it's error prone.
Console.WriteLine(a);
int value=nullable.GetValueOrDefault(-1);
if (value < 0)
{
Console.WriteLine("Maalesef İstenen Değer Bulunmamakta.");
}
else {
var b = value + value;
Console.WriteLine(b);
}
if (nullable.HasValue)
{
Console.WriteLine("Value Var");
}
else
{
Console.WriteLine("Value Yok.");
}
int ?nullable2=null;
if (nullable2.HasValue)
{
}
else
{
Console.WriteLine("Nullable 2'de value yok arkadaşım.");
}
//Work Just fine.
Nullable<int> myNullableInt = 88; //This thinks is same as int?
//Nullable value types is just works.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment