Originally Posted by Fantasy
Originally Posted by 3930K
What don't you get?
well to be honest all of it. I'm reading my C# book right now trying to understand interfaces. and I think i got the hang of it. But what I don't understand is your way. This looks really scary.
<TPanel>(TPanel p) where TPanel : Panel
If I saw that in my C# exam, I would have a heart attack. lucky for me I never took C# in college.
so I guess my question is. What is this ?!
<TPanel>(TPanel p) where TPanel
Generics. Basically, when you make an instance of a generic class, you don't do this:
SomeGenericClass c = new SomeGenericClass();
You do this:
SomeGenericClass<SomeType> c = new SomeGenericClass<SomeType>();
You have definitely used this before, unless you use ArrayLists. List is a generic type.
And then the
where TPanel : Panel
is a generic constraint. It says that you can make this generic class/call this generic method if the class specified in between the <> is a Panel. Else, it will give you a compilation error.
Extra note: Have you used LINQ? If you have, F12 to a LINQ method. You'll see that there's a <> there, but you didn't need to specify it. You may go "what?". Basically, if you have a parameter that uses that name e.g.
You can just call it like this:
Edited by 3930K - 3/16/13 at 3:35am