Rauland
Jun 1st, 2007, 04:19 PM
Hi,
Lets say I have a function,which accepts as a parameter a string.
Depending on the value of this string I would like to return a generic list of different types.
So, for instance:
Lets say I pass in the word,"dogs", well then Iīd like to return List<Dogs> mydogList = new List<Dogs>();
If I pass in the word "cars", well the same thing,return List<Cars> myCarlist = new List<Cars>();
My function I had in mind would be something similiar to:
(Please note that the code below is incorrect!)
Public List<T> MyFunction(String str)
{
switch (str)
case "Dogs":
return List<dogs> dogsList = new list<dogs>();
Case "Cars":
return List<cars> carList = new list<cars>();
}
But this obviously doesnīt work,...
Could sb please shine some light on how to improve my approach, or take a totally different one?
Thanks !
Lets say I have a function,which accepts as a parameter a string.
Depending on the value of this string I would like to return a generic list of different types.
So, for instance:
Lets say I pass in the word,"dogs", well then Iīd like to return List<Dogs> mydogList = new List<Dogs>();
If I pass in the word "cars", well the same thing,return List<Cars> myCarlist = new List<Cars>();
My function I had in mind would be something similiar to:
(Please note that the code below is incorrect!)
Public List<T> MyFunction(String str)
{
switch (str)
case "Dogs":
return List<dogs> dogsList = new list<dogs>();
Case "Cars":
return List<cars> carList = new list<cars>();
}
But this obviously doesnīt work,...
Could sb please shine some light on how to improve my approach, or take a totally different one?
Thanks !