arosas arosas - 3 months ago 16
C# Question

How do I use more than one generic type?

I know that doing the following method will return me T.

public static T SomeMethod<T>(string meh, T paramName)
{
return T;
}

/// I have come to a situation that I am returning a different type
/// I have the following mind:
public static T SomeMethod<T>(U paramName)
{
return T;
}


Any suggestions?

Answer

You can have multiple generics in one type:

public static T SomeMethod<T, U>(U paramName)
 {  
     return T;
 }

To use it:

string myString = SomeMethod<string,int>(3);