c# - About Generic types with like T -


this question has answer here:

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 (structs) can't null.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -