coldasice
coldasice

Reputation: 69

Accessing Item property using C#

I'm trying to use http://msdn.microsoft.com/en-us/library/aa289500%28v=vs.71%29.aspx

It works fine but then often I see Item in the VB version

However, button.Item doesn't exist in C#, but when I open a new project and try in VB.NET I get Item. Why is that and how can I use Item in C#?

Visual Basic

Default Public ReadOnly Property Item(ByVal Index As Integer) As _
   System.Windows.Forms.Button
   Get
      Return CType(Me.List.Item(Index), System.Windows.Forms.Button)
   End Get
End Property

C#

public System.Windows.Forms.Button this [int Index]
{
get
   {
      return (System.Windows.Forms.Button) this.List[Index];
   }
}

Upvotes: 1

Views: 354

Answers (1)

Amiram Korach
Amiram Korach

Reputation: 13296

Invoking the "Item" in C# can be done with the squared brackets:

var myButton = myButtonsArray[0];

The "[]" brackets are actually invoking the indexer which is called "Item" in VB.

Upvotes: 1

Related Questions