I'm calling string.Split() producing output string[]. I need direct
access to its enumerator, but would greatly prefer an enumerator
strings and not object types (as my parsing is unsafe casting from
object to string frequently). Basically generics and not its non-
generic counterpart.
string str1 = "abc: value1 def: value2 ghi: value3";
char[] delimiterChars = { '\t' };
string[] tokens = str1.Split(delimiterChars);
// Bad cast of course but essentially what i need
System.Collections.Generic.IEnumerator<stringtoken sEnum =
(System.Collections.Generic.IEnumerator<string>)to kens.GetEnumerator();
// Cannot use foreach as i need direct access to the enumerator within
the loop
while (tokensEnum.MoveNext())
{
string fieldValue = tokensEnum.Current; // without cast
// use tokensEnum directly below when parsing (checking for
iterator invalidation)....
}
the bad cast produces error as expected:
System.InvalidCastException was unhandled
Message="Unable to cast object of type 'SZArrayEnumerator' to type
'System.Collections.Generic.IEnumerator`1[System.String]'."