By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,338 Members | 1,351 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,338 IT Pros & Developers. It's quick & easy.

Interface with indexer

P: n/a
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?

Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.

Nov 13 '05 #2

P: n/a
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.
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.