In this source code example, we will demonstrate the usage of String.GetEnumerator() method in C# with an example.
The C# String.GetEnumerator() method is used to convert a string object into a char enumerator. It returns an instance of CharEnumerator. Once you got CharEnumerator then you can iterate the string through the loop.
C# String GetEnumerator Method Example
The following example demonstrates the String.GetEnumerator() method:
using System;
public class StringDemo
{
public static void Main(string[] args)
{
string s1 = "sourcecodeexamples";
CharEnumerator ch = s1.GetEnumerator();
while(ch.MoveNext()){
Console.WriteLine(ch.Current);
}
}
}
Output:
s
o
u
r
c
e
c
o
d
e
e
x
a
m
p
l
e
s
Related C# String Examples
- C# String Clone Method Example
- C# String Compare Method Example
- C# String CompareTo Method Example
- C# String Concat Method Example
- C# String Contains Method Example
- C# String Copy Method Example
- C# String CopyTo Method Example
- C# String EndsWith Method Example
- C# String Equals Method Example
- C# String GetEnumerator Method Example
- C# String GetHashCode Method Example
- C# String IndexOf Method Example
- C# String Insert Method Example
- C# String Intern Method Example
- C# String IsNullOrEmpty Method Example
- C# String IsNullOrWhiteSpace Method Example
- C# String LastIndexOf Method Example
- C# String Clone Method Example
- C# String Compare Method Example
- C# String CompareTo Method Example
- C# String Concat Method Example
- C# String Contains Method Example
- C# String Copy Method Example
- C# String CopyTo Method Example
- C# String EndsWith Method Example
- C# String Equals Method Example
- C# String GetEnumerator Method Example
- C# String GetHashCode Method Example
- C# String IndexOf Method Example
- C# String Insert Method Example
- C# String Intern Method Example
- C# String IsNullOrEmpty Method Example
- C# String IsNullOrWhiteSpace Method Example
- C# String LastIndexOf Method Example
Comments
Post a Comment