How to parse a string into a nullable int in C#
To parse a string into a nullable int we can use the int.TryParse()
method in c#.
Here is an example:
public static int? ToNullableInt(this string s)
{
int i;
if (int.TryParse(s, out i)) return i;
return null;
}