I want to convert a List
to a List
.
Here is my code:
void Convert(List stringList)
{
If you don't want to use Linq (which I always find hard to understand), your code looks right, but of course you need to return something:
List Convert(List stringList)
{
List intList = new List();
for (int i = 0; i < stringList.Count; i++)
{
intList.Add(int.Parse(stringList[i]));
}
return intList;
}
Be aware that this will throw an exception if the string list contains something that is not parseable as an int.
Edit: Better yet, use a foreach loop:
List Convert(List stringList)
{
List intList = new List();
foreach(String s in stringList)
{
intList.Add(int.Parse(s));
}
return intList;
}