EventDescriptorCollection.Count 屬性

定義

取得這個集合中事件描述項的數目。

public:
 property int Count { int get(); };
public int Count { get; }
member this.Count : int
Public ReadOnly Property Count As Integer

屬性值

這個集合中事件描述項的數目。

實作

範例

下列程式代碼範例會 Count 使用 屬性來列印附加至 button1的事件數目。 它要求 button1 已在表單上具現化 和 textBox1

private:
   void GetCount()
   {
      // Creates a new collection and assigns it the events for button1.
      EventDescriptorCollection^ events = TypeDescriptor::GetEvents( button1 );
      
      // Prints the number of events on button1 in a text box.
      textBox1->Text = events->Count.ToString();
   }
private void GetCount() {
    // Creates a new collection and assigns it the events for button1.
    EventDescriptorCollection events = TypeDescriptor.GetEvents(button1);
 
    // Prints the number of events on button1 in a text box.
    textBox1.Text = events.Count.ToString();
 }
Private Sub GetCount()
    ' Creates a new collection and assigns it the events for button1.
    Dim events As EventDescriptorCollection = TypeDescriptor.GetEvents(button1)
    
    ' Prints the number of events on button1 in a text box.
    textBox1.Text = events.Count.ToString()
End Sub

備註

Count屬性可用來設定迴圈的限制,以逐一查看 物件的集合。 如果集合是以零起始,請務必使用 Count - 1 作為迴圈的上限。

注意

HostProtectionAttribute 用至這個類別的屬性具有下列 Resources 屬性值: SynchronizationHostProtectionAttribute 不會影響桌面應用程式 (這些應用程式的啟動方式一般都是按兩下圖示、輸入命令或在瀏覽器輸入 URL)。 如需詳細資訊,請參閱 HostProtectionAttribute 類別或 SQL Server 程式設計和主機保護屬性

適用於

另請參閱