I assumed it's of type Match
, but that's not correct because I'm getting the error
Cannot implicitely convert type type 'System.Collections.IEnumerator' to type 'System.Collections.Generic.IEnumerator
on the line
IEnumerator<Match> friendsULsEnumerator = friendsULs.GetEnumerator();
where friendsULs
is of type MatchCollection
. I tried doing
var friendsULsEnumerator = friendsULs.GetEnumerator();
and hovering over the var
to see if Visual Studio told me the specific type, but it only showed IEnumerable
. :(
To broaden my question to my greater problem, I'm trying to get the values Donald Trump, Hillary Clinton, etc. out of a string
<h2>Friends</h2><ul><li>Donald Trump</li><li>Hillary Clinton</li>...</ul>
which occurs only once in a larger string. So what I have is
MatchCollection friendsULs = DataReader._fregx.Matches(sr.ReadToEnd());
if ( friendsULs.Count != 1 ) throw new Exception(String.Format("Couldn't find exactly one piece of HTML matching {0}",
DataReader._fregx.ToString()));
IEnumerator<Match> friendsULsEnumerator = friendsULs.GetEnumerator();
if ( friendsULsEnumerator.MoveNext() ) { } // because MoveNext() returns a bool, this useless block is necessary
MatchCollection friendsLIs = DataReader._lregx.Matches(friendsULsEnumerator.Current.ToString());
but maybe you can suggest a more compact and elegant way of doing that entirely.