Phương thức CharEnumerator.ToString () trong C # nhận một chuỗi đại diện cho đối tượng hiện tại.
Cú pháp
Sau đây là cú pháp -
public virtual string ToString();
Ví dụ
Bây giờ chúng ta hãy xem một ví dụ để triển khai phương thức CharEnumerator.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);
}
} Đầu ra
Điều này sẽ tạo ra kết quả sau -
HashCode = 31020903 Get the Type = System.CharEnumerator String representation = System.CharEnumerator T h i s i s i t ! This is it!