CharEnumerator.Clone 方法
定义
创建当前 CharEnumerator 对象的副本。Creates a copy of the current CharEnumerator object.
public:
virtual System::Object ^ Clone();
public object Clone ();
abstract member Clone : unit -> obj
override this.Clone : unit -> obj
Public Function Clone () As Object
返回
Object,是当前 CharEnumerator 对象的副本。An Object that is a copy of the current CharEnumerator object.
实现
注解
返回值是此实例的副本 CharEnumerator 及其当前状态。The return value is a copy of this instance of CharEnumerator and its current state. 这对于在遍历对象时保存状态很有用 String 。This is useful for saving your state while iterating through a String object.
例如,假设应用程序使用的原始实例 CharEnumerator 来循环访问中的每个字符 String 。For example, suppose your application uses an original instance of CharEnumerator to iterate through each character in a String. 当遇到一些唯一字符时,应用程序会暂停处理并调用 Clone 方法。When some unique character is encountered, your application pauses processing and invokes the Clone method. 实际上,这会 CharEnumerator 将对象的索引保存在中 String 。In effect, this saves the CharEnumerator object's index in the String.
应用程序使用该克隆导航到的另一部分, String 以执行一些辅助处理。Your application uses the clone to navigate to another part of the String to perform some auxiliary processing. 此导航的副作用是克隆无法跟踪处理停止的位置。The side-effect of this navigation is the clone loses track of the position where processing stopped. 不过,辅助处理完成后,应用程序会丢弃克隆,并使用原始 CharEnumerator 实例继续处理 String 原始处理停止的位置。However, when the auxiliary processing is complete, your application discards the clone and uses the original CharEnumerator instance to resume working on the String where the original processing stopped.
备注
实现此方法是为了支持 ICloneable 接口。This method is implemented to support the ICloneable interface.