เมธอด CharEnumerator.ToString() ใน C# คืนค่าสตริงที่แสดงออบเจ็กต์ปัจจุบัน
ไวยากรณ์
public virtual string ToString();
ตัวอย่าง
using System;
public class Demo
{
public static void Main()
{
string strNum = "This is it!";
CharEnumerator ch = strNum.GetEnumerator();
Console.WriteLine("HashCode = " + ch.GetHashCode());
Console.WriteLine("Get the Type = " + ch.GetType());
Console.WriteLine("\nString representation = " + ch.ToString());
while (ch.MoveNext())
Console.Write(ch.Current + " ");
ch.Reset();
Console.WriteLine();
while (ch.MoveNext())
Console.Write(ch.Current);
}
}
ผลลัพธ์
HashCode = 31020903
Get the Type = System.CharEnumerator
String representation = System.CharEnumerator
T h i s i s i t !
This is it!
คำอธิบาย: ToString() ของ CharEnumerator คืนชื่อประเภท ไม่ใช่เนื้อหาสตริง ใช้ MoveNext() และ Current เพื่อวนลูปอ่านตัวอักษร