PropertyDescriptorCollection.IDictionary.GetEnumerator 方法
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
傳回這個類別的列舉值。
virtual System::Collections::IDictionaryEnumerator ^ System.Collections.IDictionary.GetEnumerator() = System::Collections::IDictionary::GetEnumerator;
C#
System.Collections.IDictionaryEnumerator IDictionary.GetEnumerator ();
abstract member System.Collections.IDictionary.GetEnumerator : unit -> System.Collections.IDictionaryEnumerator
override this.System.Collections.IDictionary.GetEnumerator : unit -> System.Collections.IDictionaryEnumerator
Function GetEnumerator () As IDictionaryEnumerator Implements IDictionary.GetEnumerator
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";
}
}
C#
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
產品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |