How to get the default value of the Generic object

29 Apr 2014, 03:01 AM

.Net provides a default(ClassName) method to get the default value of the object or class. e.g

 var v1 = default(int); // returns 0

 var v2 = default(int?); // returns null

 var v3 = default(Student); // returns null

For Generic we can use T as the name of class. where T is the name of variable that you mentioned with your generic class/method

var v1 = default(T); // returns the defualt value of the object

Related Contents

15 May 2014, 08:07 AM
C#, LINQ, List
15 May 2014, 07:54 AM
C#, LINQ, List
29 Apr 2014, 03:07 AM
C#, Generic
About
Explains how to return the default value of Generic variable T, when T can be a value type or reference type.

Date Posted 29 Apr 2014, 02:51 AM
Author Brainy Solutions
Views 709
;