CharEnumerator.Clone() Method in C#


The CharEnumerator.Clone() method in C# is used to create a copy of the current CharEnumerator object.

Syntax

public object Clone();

Let us now see an example to implement the CharEnumerator.Clone() method −

Example

using System;
public class Demo {
   public static void Main(){
      string strNum = "356";
      CharEnumerator ch = strNum.GetEnumerator();
      while (ch.MoveNext()){
         Console.Write(ch.Current + " ");
         CharEnumerator enumClone = (CharEnumerator)ch.Clone();
         while (enumClone.MoveNext())
            Console.Write(enumClone.Current + " ");
         Console.WriteLine();
      }
   }
}

Output

This will produce the following output −

3 5 6
5 6
6

Updated on: 04-Nov-2019

31 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements