Usage of default (type):


Found an interesting use of the default keyword in .Net.

default(type) would return the default value for the datatype specified as parameter.

This is nothing but a wrapper around the default values of various types which was intended to be used for Generic classes.

T obj = default(T);

Where T can be any datatype even DataTime and GUID which need to be not NULL.

Using ‘default’ here makes sure the correct initialization takes place.

Leave a comment