Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I define a method with two Generic types and two type constraints?

Tags:

c#

generics

My Method define is

public ActionResult _Create3<T>() where T:IMyClass, new()

but I want define tow generic type

public ActionResult _Create3<T, G>(G content) where T:IMyClass, new()

Type G must also use interface ImyClass but I Dont know define in where tow type !!!

for example if may be write :

public ActionResult _Create3<T, G>(G content) where {T:IMyClass, G:IMyClass}, new()

but get error.

thanks for answer

like image 487
khoshghadam Avatar asked Dec 13 '25 22:12

khoshghadam


1 Answers

Add another where constraint for that generic type:

public ActionResult _Create3<T, G>(G content) 
  where T : IMyClass, new()
  where G : IMyClass, new()
like image 167
Grant Thomas Avatar answered Dec 15 '25 11:12

Grant Thomas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!