次の方法で共有


EventDescriptorCollection.Count プロパティ

定義

コレクション内のイベント記述子の数を取得します。

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

プロパティ値

コレクション内のイベント記述子の数。

実装

次のコード例では、 Count プロパティを使用して、 button1にアタッチされたイベントの数を出力します。 フォームで button1textBox1 がインスタンス化されている必要があります。

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();
   }
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 プロパティを使用して、オブジェクトのコレクションを反復処理するループの制限を設定できます。 コレクションが 0 から始まる場合は、ループの上限として Count - 1 を使用してください。

このクラスに適用される HostProtectionAttribute 属性には、次の Resources プロパティ値があります: SynchronizationHostProtectionAttributeはデスクトップ アプリケーションには影響しません (通常、アイコンをダブルクリックするか、コマンドを入力するか、ブラウザーで URL を入力します)。 詳細については、 HostProtectionAttribute クラスまたは SQL Server プログラミング属性とホスト保護属性に関するページを参照してください。

適用対象

こちらもご覧ください