Generic Code

default keyword in c#

The “Default” keyword in c# can be used in the following scenarios .

The main use of default comes in to picture when used in the generic code.

1. To return Type’s Default Value

The Default returns the type’s default value.

For the Integer , it returns 0 , for Boolean , it returns false and for the reference types , it returns null

int valueI = default(Int32);

bool ValueB = default(Boolean);

string senthil = default(String);

MessageBox.Show(valueI.ToString()) ;// "0"

MessageBox.Show(ValueB.ToString()); // "False"

MessageBox.Show(senthil); // nothings

There is another way to get the default value via the following example.


read more