patterncsharpCritical
C# generics syntax for multiple type parameter constraints
Viewed 0 times
genericsconstraintssyntaxparameterformultipletype
Problem
Possible Duplicate:
Generic methods and multiple constraints
I need a generic function that has two type constraints, each inheriting from a different base class. I know how to do this with one type:
However, I don't know how to do this with two types:
How do you do this? (using .NET 2)
Generic methods and multiple constraints
I need a generic function that has two type constraints, each inheriting from a different base class. I know how to do this with one type:
void foo() where T : BaseClassHowever, I don't know how to do this with two types:
void foo() where TOne : BaseOne // and TTwo : BaseTwo ???How do you do this? (using .NET 2)
Solution
void foo()
where TOne : BaseOne
where TTwo : BaseTwoMore info here:
https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/constraints-on-type-parameters#constraining-multiple-parameters
Code Snippets
void foo<TOne, TTwo>()
where TOne : BaseOne
where TTwo : BaseTwoContext
Stack Overflow Q#965580, score: 896
Revisions (0)
No revisions yet.