Showing posts with label Generics. Show all posts
Showing posts with label Generics. Show all posts

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.

Sunday, February 20, 2011

Generic Constraints

class SortedList where T: IComparable , new()
{...}

In C# we have generic constraints like this to indicate a where clause to which the class must comply.

Here sortedlist is using a type T. This type must implement the Icomparable interface. The new() states that the type T must have a constructor.

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...