Using GetEnumerator to access characters in C# string

Below is an example of using GetEnumerator method of a collection to access characters in a string and display them.

var enumerator = "This is my string".GetEnumerator();
while (enumerator.MoveNext())
  var element = enumerator.Current ;
  Console.WriteLine (element);

Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.