This post originated from an RSS feed registered with .NET Buzz
by Peter G Provost.
Original Post: Specifying Requirements w/ C# Generics
Feed Title: Peter Provost's Geek Noise
Feed URL: /error.aspx?aspxerrorpath=/Rss.aspx
Feed Description: Technology news, development articles, Microsoft .NET, and other stuff...
In my post 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 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);
I'm not 100% sure of this, but based on my experience with C++ templates I would suggest
that there is 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?