Rants, rambles, news and notes from another geek

Specifying Requirements W/ C# Generics

In my post&nbsp_place_holder;More Tricks w/ C# Generics, I re-posted Don Box’s sample that demonstrated the use of the where clause in a generic definition.

Don’s code was:

public delegate void EventHander<S, T>(S sender, T args) where T : EventArgs;

Brett&nbsp_place_holder;Knights asked in the comments of my post what the difference is between Don’s code and this:

public delegate void EventHander<S>(S sender, EventArgs args);&nbsp_place_holder;&nbsp_place_holder;

I’m not 100% sure of this, but based on my experience with C++ templates I would suggest that there is&nbsp_place_holder;a significant difference between Brett’s example and Don’s. In the former example, you are saying that T should be derived from EventArgs, but within your method T is still “untyped”. In other words you can access any public method on T, not just those defined in EventArgs.

In Brett’s example you would only be able to call the public methods defined in the EventArg class.

Am I right here? Anyone who actually has Whidbey care to comment?