c# - About Generic types with like T -
this question has answer here:
- what “where t : class, new()” mean? 11 answers
i wonder this? kind of generic method think. has part 'where'. that? there generic classes i've heard. how can learn these can recommend article?
protected t item<t>() t : class { return getdataitem() t ?? default(t); }
the where
clause called "generic constraint". in case, where t: class
dictates t must reference type (i.e., not struct
).
more info on generic constraints: http://msdn.microsoft.com/en-us/library/d5x73970.aspx , generic classes: http://msdn.microsoft.com/en-us/library/sz6zd40f.aspx
edit
in snippet provided, constraint needed because otherwise null-coalescing operator (??) wouldn't make sense, since value types (struct
s) can't null.
Comments
Post a Comment