Let's say there are different Contracts C1, C2, C3,.... Cn.
Now I have a method which looks like below:
public List<Cn> M(string param1, string param2)
{
switch(param2)
case value1:
var list1 = new List<C1>();
list.Add(new C1());
return list;
break;
case value2:
var list2 = new List<C2>();
list.Add(new C2());
return list2;
break;
default:
return null;
break;
}
This method calls a DB method which fetches data based on the param2 and create list of specific objects and returns the same. Now for different values of param2 it will send list of different Type of objects. How to achieve this? In generic or some other approach, any help would be appreciated.
Update:
C1 and C2 may be different in structure.
Class C1
{
int i;
string j;
}
Class C2
{
string i;
string j;
}