Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Make generic method that takes 2 different generic types in c# is it

I’m trying to make method that reads 3 different lists, but they should be generic.
We know that a generic list can be read like:

public void msgList<T>(List<T> readlist)
{
//do something with generic readlist, as long as T is Int, double or something else
}

But suppose you want to read 2 arguments in that method, and that one is a list of integers, and another is a list of doubles for example

public void msgList<T>(List<T> readlist, List<T> readsecondlist)
{
//do something with generic readlist and readsecondlist
}

I intend in the above that the readlist is of integers, and readsecondlist is a list of doubles, or any other generic type. Is something like this possible?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Kind regards,

>Solution :

You can have multiple generic type parameters :

public void msgList<TFirst, TSecond>(List<TFirst> readlist, List<TSecond> readsecondlist)
{
    //do something with generic readlist and readsecondlist
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading