CharEnumerator.Dispose() วิธีการใน C # ใช้เพื่อปล่อยทรัพยากรทั้งหมดที่ใช้โดยอินสแตนซ์ปัจจุบันของคลาส CharEnumerator
ไวยากรณ์
public void Dispose ();
ให้เราดูตัวอย่างการใช้วิธี CharEnumerator.Dispose() -
ตัวอย่าง
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);
}
} ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
3 5 6