In C# what does where T : class
mean?
Ie.
public IList DoThis() where T : class
It is a generic type constraint. In this case it means that the generic type T
has to be a reference type (class, interface, delegate, or array type).
That restricts T
to reference types. You won't be able to put value types (struct
s and primitive types except string
) there.
it means that the type used as T
when the generic method is used must be a class - i.e. it cannot be a struct or built in number like int
or double
// Valid:
var myStringList = DoThis<string>();
// Invalid - compile error
var myIntList = DoThis<int>();
'T' represents a generic type. It means it can accept any type of class. The following article might help:
http://www.15seconds.com/issue/031024.htm