khoshghadam
khoshghadam

Reputation: 89

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

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

Upvotes: 2

Views: 534

Answers (2)

Teoman Soygul
Teoman Soygul

Reputation: 25742

You can define multiple where constraints on multiple generic types like:

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

Upvotes: 4

Grant Thomas
Grant Thomas

Reputation: 45058

Add another where constraint for that generic type:

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

Upvotes: 7

Related Questions