In order to allow null values to an integer or for any value types , we need to make the data type as Nullable<T> where T refers to type.
How to Allow Null Values for Integer in C# ?
There are 2 ways you can set null value to value types in C# .
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AbundantcodeConsole { class Program { static void Main(string[] args) { Nullable<int> Marks1; int? Marks2; Console.ReadLine(); } } }
Leave a Reply