We cannot assign null values to generics. The reason behind this is a generic might take a reference type or value type. As we know value types cannot be assigned with null value. How can we overcome this?.
We can us the default keyword with generics. Then reference types will be assigned with null if a value is not there and a value type would be given it's appropriate value.
T Name = Default(T);
Here T is a generic variable.
No comments:
Post a Comment