Interface with indexer

G

Guy

I am writing an interface that will be implemented on
collection type objects.

The interface was previously written in vb.net for an
application and was coded as follows

Public Interface IListEditorCollection

Function ToString() As String
Function Add() As IListEditorItem
Default ReadOnly Property Item(ByVal Index As Int32)
As IListEditorItem
ReadOnly Property ItemByPK(ByVal ID As Int32) As
IListEditorItem
ReadOnly Property Count() As Int32

End Interface

As you can see the interface defines two properties that
take parameters.
I am aware that C# provides this functionality by using
the 'this' keyword to provide an indexer and you can have
many different indexers by using the Runtime.IndexerName
attribute on each different property declaration.

What i am stuck with is how do i define these in C# for my
interface?
 
T

Tian Min Huang

Hi,

Please refer to the following:

//----------code snippet--------------
using System;
using System.collections;

interface IListEditorCollection
{
String Tostring();
IListEditorItem Add();
protected Arraylist Item=new ArrayList ();
protected Arraylist ItemByPK=new ArrayList ();
protected Int32 count;

public object this[Int32 idx]
{
get
{
....
return Item[idx];
}
}

public object this[Int32 ID]
{
get
{
....
return ItemByPK[ID];
}
}

public Int32 Count
{
get
{
return count;
}
}
}

//------------end of ---------------------

Hope this helps.

Regards,
HuangTM
This posting is provided "AS IS" with no warranties, and confers no rights.
 
T

Tian Min Huang

Hi,

Thanks for your update. I am very glad to hear that you have resolved the
problem.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! ¨C www.microsoft.com/security
This posting is provided ¡°as is¡± with no warranties and confers no rights.
 

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

Top