BindingContext.IEnumerable.GetEnumerator 方法

定义

获取集合的枚举数。Gets an enumerator for the collection.

 virtual System::Collections::IEnumerator ^ System.Collections.IEnumerable.GetEnumerator() = System::Collections::IEnumerable::GetEnumerator;
System.Collections.IEnumerator IEnumerable.GetEnumerator ();
Function GetEnumerator () As IEnumerator Implements IEnumerable.GetEnumerator

返回

集合的 IEnumeratorAn IEnumerator for the collection.

实现

示例

下面的代码示例使用 IEnumerable.GetEnumerator 方法返回 BindingContextIEnumeratorThe following code example uses the IEnumerable.GetEnumerator method to return an IEnumerator for the BindingContext.

private:
   void GetManagerEnumerator()
   {
      IEnumerator^ myEnumerator;
      myEnumerator = ( (IEnumerable^)(this->BindingContext) )->GetEnumerator();
      ForEachEnumerator();
   }

   void ForEachEnumerator()
   {
      for each ( IEnumerator^ myEnumerator in ( (IEnumerable^)(this->BindingContext) ) )
      {
         Console::WriteLine( myEnumerator );
      }
   }
private void GetManagerEnumerator(){
   IEnumerator myEnumerator;
   myEnumerator = ((IEnumerable)this.BindingContext).GetEnumerator();
   ForEachEnumerator();
}

private void ForEachEnumerator(){
   foreach( IEnumerator myEnumerator in this.BindingContext){
      Console.WriteLine(myEnumerator.ToString());
   }
} 
Private Sub GetManagerEnumerator()
   Dim myEnumerator As IEnumerator
   myEnumerator = CType(BindingContext,IEnumerable).GetEnumerator()
   ForEachEnumerator()
End Sub

Private Sub ForEachEnumerator()
   Dim myEnumerator As IEnumerator
   For Each myEnumerator In CType(BindingContext,IEnumerable)
      Console.WriteLine(myEnumerator.Current.ToString())
   Next
End Sub 

注解

通过 IEnumerable.GetEnumerator 方法返回的 IEnumerator,您可以循环访问 BindingContext管理的集合。The IEnumerator returned by the IEnumerable.GetEnumerator method allows you to iterate over the collection managed by the BindingContext.

适用于