C# – Enum generic type constraint

In C# 7.3, Microsoft added the ability to specify an Enum as a generic constraint, like this: Whenever you have a generic method, it’s a good idea to use generic type constraints. Without constraints, you would have to implement type checking in the generic method and throw exceptions if an invalid type was used. With … Read more

Error: Cannot convert null to type parameter ‘T’

Problem You’re trying to return null from a generic method and you’re getting the following compiler error: Cannot convert null to type parameter ‘T’ because it could be a non-nullable value type. Consider using ‘default(T)’ instead You can’t return null because the compiler doesn’t know if T is nullable. Solution There are a few options … Read more