PropertyDescriptorCollection.GetEnumerator 方法

返回该类的枚举数。

**命名空间:**System.ComponentModel
**程序集:**System(在 system.dll 中)

语法

声明
Public Overridable Function GetEnumerator As IEnumerator
用法
Dim instance As PropertyDescriptorCollection
Dim returnValue As IEnumerator

returnValue = instance.GetEnumerator
public virtual IEnumerator GetEnumerator ()
public:
virtual IEnumerator^ GetEnumerator ()
public IEnumerator GetEnumerator ()
public function GetEnumerator () : IEnumerator

返回值

IEnumerator 类型的枚举数。

示例

下面的代码示例获取 button1 上属性的枚举数。它使用该枚举数来输出集合中属性的名称。它要求已在窗体上实例化 button1textBox1

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
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:
   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.get_Current();
        textBox1.set_Text(myProperty.ToString() + '\n');
    }
} //MyEnumerator

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

PropertyDescriptorCollection 类
PropertyDescriptorCollection 成员
System.ComponentModel 命名空间
PropertyDescriptor 类
TypeDescriptor
IEnumerator