EventDescriptorCollection.Count プロパティ

定義

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

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

プロパティ値

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

実装

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

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

注意

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

適用対象

こちらもご覧ください