Skip to main content
Format code as code.
Source Link
Kenny Evitt
  • 9.9k
  • 7
  • 74
  • 96

Just do two things to your original code. Remove – remove the wherewhere constraint, and change the last returnreturn from return nullreturn null to return default(T)return default(T). This way you can return whatever type you want.

By the way, you can avoid the use of "is"is by changing your ifif statement to if (columnValue != DBNull.Value)if (columnValue != DBNull.Value).

Just do two things to your original code. Remove the where constraint, and change the last return from return null to return default(T). This way you can return whatever type you want.

By the way, you can avoid the use of "is" by changing your if statement to if (columnValue != DBNull.Value).

Just do two things to your original code – remove the where constraint, and change the last return from return null to return default(T). This way you can return whatever type you want.

By the way, you can avoid the use of is by changing your if statement to if (columnValue != DBNull.Value).

Source Link
Robert C. Barth
  • 23.4k
  • 6
  • 49
  • 53

Just do two things to your original code. Remove the where constraint, and change the last return from return null to return default(T). This way you can return whatever type you want.

By the way, you can avoid the use of "is" by changing your if statement to if (columnValue != DBNull.Value).