I have a simple method:
public static T GetValue<T>(SqlDataReader reader, int columnIndex, T defaultValue = default(T)) { return reader.IsDBNull(columnIndex) ? defaultValue : (T)reader[columnIndex]; } and usage of it:
string s = SqlUtils.GetValue<string>(reader, nameOrd); I asked myself, why do I have to specify <string> if it's clear from usage that type of the returned parameter is string? But apparently I have to because otherwise compiler complains The type arguments cannot be inferred from the usage.... Where is my logic fails?
T GetValue<T>() { return default(T); }..