Tuesday, June 21, 2011

Assigning Null Values to Generics - Is it Allowed

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

Retrieving Calendar of a Bookable Resource in Dynamics

There are occasions where we need to retrieve working days and working times of a resource in Dynamics grammatically. This is quite possible...