CharEnumerator.Dispose() Method in C#


The CharEnumerator.Dispose() method in C# is used to release all resources used by the current instance of the CharEnumerator class.

Syntax

public void Dispose ();

Let us now see an example to implement the CharEnumerator.Dispose() 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 + " ");
      // disposed
      ch.Dispose();
      // this will show an error since we disposed the object above
      // Console.WriteLine(ch.Current);
   }
}

Output

This will produce the following output −

3 5 6

Updated on: 04-Nov-2019

56 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements