Possible Duplicate:
How to get the index of an element in an IEnumerable?
i have this following function that accepts ienumerable string list.
I loop through all the strings and if its value equals "TestName
" (case insensitive), i return its position.
int GetMyTestColumnPosition(IEnumerable<string> TitleNames)
{
foreach (var test in TitleNames)
{
if (string.Compare(test, "testname", stringComparison.CurrentCultureIgnoreCase) == 0)
{
// return TitleNames.IndexOf(test); does not work!
}
}
}
EDIT: I changed the parameter to "IList<string>
" and this works! But,
- How to find index or position of a string within an ienumerable string list ?
- Why does the ienumerable does not support index ? (we are not changing any value with in the list, we are just finding out its position!)