I am trying to access each element in a List<string> list and split each element in the list in my below code.
for(int i = 0; i < list.Count; i++)
{
string x= list[i].ToString();
string y= x.Split(':');
}
But this is not working, the reason shown is “Cannot implicitly convert string[] to string”. How Do i fix this? When i store list[i] in a string variable, will it be considered as a string array instead of string?
When you call
string.Split, it will return an array of strings which comprise the components of the string which were delimited by':'. You need to changestring y= x.Split(':');to this:See the documentation for the method