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