Created
January 5, 2022 08:20
-
-
Save anilkay/e109031dbf68895816b5b45fc19c7ecc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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