string type c# as nullable int code example
Example 1: set int to null c#
// Nullable types add null as a valid value in addition to the type range
Nullable<int> i = null;
// Can also be written as:
int? i = null;
Example 2: c# check if int is null
// When trying to check if your int is null or i.e. 'not set',
// you will get the following error:
// The result of the expression is always 'false'
// since a value of type 'int' is never equal to 'null' of type 'int?'
// You can however bypass this by converting your int to string:
int myInt = null;
// This Method will return a bool;
bool isNullInt = string.IsNullOrEmpty(myInt.ToString());
// isNullInt will be in this case true