Multiple Generic Constraint Syntax?
-
Is there a legitimate syntax for declaring a generic class taking multiple generic parameters, specifying constraints on *each* parameter? For instance, VS2005 will not complain about multiple constraint parameters and a *singular* constraint (where) expression:
public class MyGeneric<T1, T2> : Component where T1 : Class1 { }
But it doesn't want to see the following:
public class MyGeneric<T1, T2> : Component where T1 : Class1, where T2 : Class2 { }
Does anybody know the syntax for multiple generic constraints? TIA, m
-
Is there a legitimate syntax for declaring a generic class taking multiple generic parameters, specifying constraints on *each* parameter? For instance, VS2005 will not complain about multiple constraint parameters and a *singular* constraint (where) expression:
public class MyGeneric<T1, T2> : Component where T1 : Class1 { }
But it doesn't want to see the following:
public class MyGeneric<T1, T2> : Component where T1 : Class1, where T2 : Class2 { }
Does anybody know the syntax for multiple generic constraints? TIA, m
Just omit the comma: public class MyGeneric : Component where T1 : Class1 where T2 : Class2
David Anton www.tangiblesoftwaresolutions.com Instant C#: VB to C# converter Instant VB: C# to VB converter Instant C++: C# to C++ converter, VB to C++ converter Instant Python: C# to Python converter, VB to Python converter
-
Just omit the comma: public class MyGeneric : Component where T1 : Class1 where T2 : Class2
David Anton www.tangiblesoftwaresolutions.com Instant C#: VB to C# converter Instant VB: C# to VB converter Instant C++: C# to C++ converter, VB to C++ converter Instant Python: C# to Python converter, VB to Python converter
Wow, thanks! Funny, you have to comma delimit the new constraint after another constraint... public class MyCollection<T1, T2> : Component where T1: MyClass1, new() where T2 : MyClass2 ...but not the where of the subsequent constraint? :-) Sure does work. I appreciate the tip. m