Three options:
- Return
default(ordefault(T)for older versions of C#) which means you’ll returnnullifTis a reference type (or a nullable value type),0forint,'\0'forchar, etc. (Default values table (C# Reference)) - If you’re happy to restrict
Tto be a reference type with thewhere T : classconstraint and then returnnullas normal - If you’re happy to restrict
Tto be a non-nullable value type with thewhere T : structconstraint, then again you can returnnullas normal from a method with a return value ofT?– note that this is not returning a null reference, but the null value of the nullable value type.