473,385 Members | 1,333 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Interface with indexer

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
2 4672
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Yoramo | last post by:
Hello I have a class the containes several ArrayList's and I whold like to use a indexer for each one. I'm getting a compilation error. "already defines a member called 'this' with the same...
7
by: Oren | last post by:
hi I have created a class with a simple indexer what is the syntax for adding the function "Remove" ... myClass.colors=Color.Black; // WORKS O myClass.colors.Remove(); // ?? .......
7
by: Steph | last post by:
I'm learning C#. I need to implement an indexer using an array list. I have the following code and I'm getting an error "Inconsistent accessibility: indexer return type CRegs is less accessible...
8
by: Razzerroo | last post by:
Hello all I'm currently converting me and our code from VB.NET to C# for the company I work for. I have an VB.NET interface that has an excerpt like this: Public Interface...
5
by: Clive Dixon | last post by:
Is it possible to access an indexer of a base class with identical signature, e.g. class Class1 { public object this { get { // ...
3
by: Nash Alexx | last post by:
Hello! I am quite new to C#, and one concept that really gives me a headache is "indexer". I have gone through the MSDN examples, and, at some level know how to use indexers. But, the thing is I...
17
by: SemSem | last post by:
i want to know waht is an index and how we use it with a simple example including the main of the program . thanx -- Islam Khalil,
4
by: Brian | last post by:
I really want to use the IDataErrorInfo interface. I'm using it now in combination with an ErrorProvider and this seems really good. But the downside: IDataErrorInfo wants to use a string...
1
by: recherche | last post by:
Hola! I tried the following public implementation of interface indexer by struct (Code Snippet 1) in private and explicit implementation by struct (Code Snippet 2) but in vain. Please help! ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.