Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C#

Phương thức CharEnumerator.ToString() trong C#

Phương thức CharEnumerator.ToString() trong C# lấy chuỗi biểu diễn đối tượng hiện tại.

Cú pháp

public virtual string ToString();

Ví dụ

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("Lấy Type = " + ch.GetType());
        Console.WriteLine("\nBiểu diễn chuỗi = " + ch.ToString());
        while (ch.MoveNext())
            Console.Write(ch.Current + " ");
        ch.Reset();
        Console.WriteLine();
        while (ch.MoveNext())
            Console.Write(ch.Current);
    }
}

Kết quả

HashCode = 31020903
Lấy Type = System.CharEnumerator
Biểu diễn chuỗi = System.CharEnumerator
T h i s i s i t !
This is it!