Home > ASP.NET > Usage of default (type):

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.

Advertisements
Categories: ASP.NET
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: