PropertyDescriptorCollection.GetEnumerator 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
傳回這個類別的列舉值。
public:
virtual System::Collections::IEnumerator ^ GetEnumerator();
public virtual System.Collections.IEnumerator GetEnumerator ();
abstract member GetEnumerator : unit -> System.Collections.IEnumerator
override this.GetEnumerator : unit -> System.Collections.IEnumerator
Public Overridable Function GetEnumerator () As IEnumerator
傳回
IEnumerator 型別的列舉程式。
實作
範例
下列程式代碼範例會取得 上 button1
屬性的列舉值。 它會使用列舉值來列印集合中屬性的名稱。 它要求 button1
已在表單上具現化 和 textBox1
。
private:
void MyEnumerator()
{
// Creates a new collection and assigns it the properties for button1.
PropertyDescriptorCollection^ properties = TypeDescriptor::GetProperties( button1 );
// Creates an enumerator.
IEnumerator^ ie = properties->GetEnumerator();
// Prints the name of each property in the collection.
Object^ myProperty;
while ( ie->MoveNext() == true )
{
myProperty = ie->Current;
textBox1->Text = textBox1->Text + myProperty + "\n";
}
}
private void MyEnumerator() {
// Creates a new collection and assigns it the properties for button1.
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(button1);
// Creates an enumerator.
IEnumerator ie = properties.GetEnumerator();
// Prints the name of each property in the collection.
Object myProperty;
while(ie.MoveNext()==true) {
myProperty = ie.Current;
textBox1.Text += myProperty.ToString() + '\n';
}
}
Private Sub MyEnumerator()
' Creates a new collection and assigns it the properties for button1.
Dim properties As PropertyDescriptorCollection = _
TypeDescriptor.GetProperties(button1)
' Creates an enumerator.
Dim ie As IEnumerator = properties.GetEnumerator()
' Prints the name of each property in the collection.
Dim myProperty As Object
While ie.MoveNext() = True
myProperty = ie.Current
textBox1.Text &= myProperty.ToString() & ControlChars.Cr
End While
End Sub