I have two string say cityIds
and cityNames
.
cityIds="1,2,3"
cityNames="Pune,Mumbai,Surat"
I have one class say City.cs
public class City
{
public int CityId { get; set; }
public string CityName { get; set; }
}
From cityIds
and cityNames
I want to create List.
So if I have Input like this
cityIds="1,2,3"
cityNames="Pune,Mumbai,Surat"
I want output like this
list[0]=CityId=1,CityName="Pune"
list[1]=CityId=2,CityName="Mumbai"
list[2]=CityId=3,CityName="Surat"
I tried this
var listOfIds = cityIds.Split(',');
var listOfNames = cityNames.Split(',');
for(int i = 0; i < listOfIds.Count; i++)
{
listOfDealerCities.Add(new City()
{
CityId = Int32.Parse(listOfIds[i]),
CityName = listOfNames[i]
});
}
Is there any better way to do this like using LINQ?