473,513 Members | 2,469 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

creating 2 indexers in dotnet 2?

hi..

i would like to create something very much like DataTable, only for it
to hold actuall objects (not their string representation)

i saw that DataTable as DataColumn Collection which has to 2 indexes,
it can bring up a columns by name or by it's ordinal number, is there
any easy way to do this, or do i need to 2 collection objects (an array
list and a Dictionary) that will hold both references

Sep 7 '06 #1
4 1076
Elhanan,

No, you just have to put two indexers on your object that is exposed:

public class MyCollection
{
public this[int index]
{
get
{

}
set
{

}
}

public this[string index]
{
get
{

}
set
{

}
}
}

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Elhanan" <em*****@hotmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
hi..

i would like to create something very much like DataTable, only for it
to hold actuall objects (not their string representation)

i saw that DataTable as DataColumn Collection which has to 2 indexes,
it can bring up a columns by name or by it's ordinal number, is there
any easy way to do this, or do i need to 2 collection objects (an array
list and a Dictionary) that will hold both references

Sep 7 '06 #2
i meant to ask how do i manage this internally?

right now i a DIctionary which saves a key as a string, and it's index
in the value part.

so if i want to retrieve the name by the index i do this:

public string this[int index]
{
get
{
foreach (KeyValuePair<string, intkvp in fields)
{
if (kvp.Value == index)
return kvp.Key;
}
throw new KeyNotFoundException("Key not Found according
To Index " + index);
}
}
Nicholas Paldino [.NET/C# MVP] wrote:
Elhanan,

No, you just have to put two indexers on your object that is exposed:

public class MyCollection
{
public this[int index]
{
get
{

}
set
{

}
}

public this[string index]
{
get
{

}
set
{

}
}
}

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Elhanan" <em*****@hotmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
hi..

i would like to create something very much like DataTable, only for it
to hold actuall objects (not their string representation)

i saw that DataTable as DataColumn Collection which has to 2 indexes,
it can bring up a columns by name or by it's ordinal number, is there
any easy way to do this, or do i need to 2 collection objects (an array
list and a Dictionary) that will hold both references
Sep 7 '06 #3
"Elhanan" <em*****@hotmail.coma écrit dans le message de news:
11**********************@e3g2000cwe.googlegroups.c om...

|i meant to ask how do i manage this internally?
|
| right now i a DIctionary which saves a key as a string, and it's index
| in the value part.
|
| so if i want to retrieve the name by the index i do this:

Just use two dictionaries, one in either direction and keep them in sync.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Sep 7 '06 #4
SP
"Elhanan" <em*****@hotmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
hi..

i would like to create something very much like DataTable, only for it
to hold actuall objects (not their string representation)

i saw that DataTable as DataColumn Collection which has to 2 indexes,
it can bring up a columns by name or by it's ordinal number, is there
any easy way to do this, or do i need to 2 collection objects (an array
list and a Dictionary) that will hold both references
KeyedCollection<TKey, TItemprovides indexing by a key and by index.

SP

Sep 7 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
1599
by: Alvin Bruney | last post by:
In later versions of the framework is it possible to have indexers on properties for member fields? Say for example I have private ArrayList blah; and a propget public object Blah
12
24731
by: Sergey Klementiev | last post by:
Why it's impossible to have a static indexer in C#?
3
2296
by: DKode | last post by:
Ok, Consider the following example: School Class - StudentCollection Property StudentCollection Class : CollectionBase - Add - Item
2
1953
by: Jim | last post by:
How does one determine what indexers are available on a given object? The only way I have found is by looking at the Object Browser. But even then it only gives a simple signature like, this....
2
2229
by: Iain | last post by:
I'm writing some reflection code which resolves the value of a complex expression (e.g. MyInfo.Customers.Orders.Date), against a specific object. I'm struggling a bit with indexers. I'm not...
1
7561
by: mdub317 | last post by:
I'm totally new to programming and I am wondering; when would be a good time to use an array or an indexer? I want to know what types of applications would make good use of arrays or indexers. ...
5
1911
by: bonk | last post by:
Hello, IL does not have indexers. Infact the c# compiler compiles indexers to Set_Item and Get_Item (or whatever name I choose via the IndexerNameAttribute ). So how does c# (compiler) know...
12
3139
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without...
3
1658
by: Benssol | last post by:
Hi all great programmers and great coders Please can anyone explain clearly the following: usage of indexers? is it used widely (in most applications)? is there is another way that do its...
0
7158
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7523
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5085
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1592
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.