Answers for "nullable types in c#"

C#
0

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;
Posted by: Guest on May-11-2020
0

c# nullable generic

static void Main(string[] args)
{
    int? i = GetValueOrNull<int>(null, string.Empty);
}


public static Nullable<T> GetValueOrNull<T>(DbDataRecord reader, string columnName) where T : struct
{
    object columnValue = reader[columnName];

    if (!(columnValue is DBNull))
        return (T)columnValue;

    return null;
}
Posted by: Guest on February-18-2020

C# Answers by Framework

Browse Popular Code Answers by Language