Yes, this can be done easily by passing a parameter of type Object, as shown below:
public void Test(int SomeCondition,Object Param) { dynamic list; switch (SomeCondition) { case 0: list = (List<int>)Param; MessageBox.Show(list[0].ToString()); break; case 1: list = (List<string>)Param; MessageBox.Show(list[0].ToString()); break; default: MessageBox.Show("Default!"); break; } }
You can call this function as follows:
List<int> list1 = new List<int>(new int[]{1,2,3}); List<string> list2 = new List<string>(new string[] { "one", "two", "three"}); Test(0, list1); Test(1, list2);
Anton Semenov
source share