CSharpFeeds - All your C# feeds in one place.

Monday, May 19, 2008

A Generic Constraint Question

by Eric Lippert via Fabulous Adventures In Coding on 5/19/2008 2:01:00 PM

Here's a question I get fairly frequently: the user desires to create a generic type Bar<T> constrained such that T is guaranteed to be a Foo<U>, for some U. The way they usually try to write this is class Bar<T>  where T : Foo<T> {... which of course then does not work. The user discovers this when they type  new Bar<Foo<string>>() and get an error stating that the constraint has been violated. Which it certainly has. The constraint says that T m ...

[ read more ]

Subscribe

New Feed

Product Spotlight

Recently Updated Sources

Legal Note

The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.

Advertise with us