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];
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top