Poperty with parameter in VB to C#

  • Thread starter Thread starter Bom
  • Start date Start date
B

Bom

hi,

I have following VB code :
default Public ReadOnly Property Item(ByVal Index As
Integer) As DataColumnHeader
Get
Return CType(list.Item(Index),DataColumnHeader)
End Get
End Property

How can I in C# pass an argument to a property (getter
accessor)?
I started as follows but thats not right.

public DataColumnHeader Item (????)
{
get
{return (DataColumnHeader)this.List.Item[???];}

}
Thanks
Bom
 
Bom said:
I have following VB code :
default Public ReadOnly Property Item(ByVal Index As
Integer) As DataColumnHeader
Get
Return CType(list.Item(Index),DataColumnHeader)
End Get
End Property

How can I in C# pass an argument to a property (getter
accessor)?

In C#, a property which takes an argument is called an indexer. You
don't get to use names with indexers, either - you can use an attribute
to specify the name which is visible to other languages, but you can
only define one indexer with any given signature. The syntax is
something like:

public DataColumnHeader this [int index]
{
get
{
return (DataColumnHeader)this.List[index];
}
}
 
Back
Top