In C# types are divded into 2 broad categories: Value types - int, float, double, structs, enums, etc. Reference types - Interface, Class, delegates, arrays, etc. by default value types are non nullable. TO make them nullable use ? int i = 0 (i is non nullable, so i cannot be set to null, i = null will generate compiler error) int? j = 0 (j is nullable int, so j = null is legal) Nullable types bridge the difference between C# types and database types Below program shows the compiler error that we get if we try to set the null value to the value types. Write a program to check is user is married or not. Set boolean variable to null while writing the program. using System ; class Program { static void Main ( ) { bool ? isMarried = null ; if ( isMarried = = true ) Console . WriteLine ( " User is married " ) ; else if ( isMarried = = true ) Console . WriteLine ( "...
Comments
Post a Comment