How do I return null value from a generic method?
protected T ValueOrDefault<T>(IDataReader reader, int ordinalId)
        {  
  Type t = typeof(reader.GetValue(ordinalId));
    if (t.IsValueType){
        //Struct. How do I return null?
    } else { 
        //Class
        //just return  null
        return  default(T);
    }
}
                default(T) works in both cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With