Brad Wood <bradley|.wood|@ndsu|.edu> wrote:
I have this method declaration:
private SomeType getSomething<T>( T spec ) where T: String, MemoryStream
The compiler error I get is:
'string' is not a valid constraint. A type used as a constraint must be
an interface, a non-sealed class or a type parameter.
I don't understand what is meant by "type parameter" in this context. I
understand a "type parameter" to be my "T" so I don't understand how a
constraint can be the same thing...
T is the type parameter, and "where T : String, MemoryStream" is the
constraint. However:
1) You can't have a constraint against two classes in the same way as
you can't derive from two classes
2) You can't constrain a type to have a "minimal base type" which is
sealed (like string)
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too