PC Review


Reply
Thread Tools Rate Thread

creating 2 indexers in dotnet 2?

 
 
Elhanan
Guest
Posts: n/a
 
      7th Sep 2006
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

 
Reply With Quote
 
 
 
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      7th Sep 2006
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]
- (E-Mail Removed)
"Elhanan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
Elhanan
Guest
Posts: n/a
 
      7th Sep 2006
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, int> kvp 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]
> - (E-Mail Removed)
> "Elhanan" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
> >


 
Reply With Quote
 
Joanna Carter [TeamB]
Guest
Posts: n/a
 
      7th Sep 2006
"Elhanan" <(E-Mail Removed)> a écrit dans le message de news:
(E-Mail Removed)...

|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


 
Reply With Quote
 
SP
Guest
Posts: n/a
 
      8th Sep 2006
"Elhanan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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, TItem> provides indexing by a key and by index.

SP

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating thumbnail from a avi/mpeg video with just dotnet 3.5? Volkan Senguel Microsoft C# .NET 4 10th Dec 2008 08:46 PM
Creating extensible applications with dotnet Jim Horvath Microsoft VB .NET 3 22nd Dec 2007 06:15 PM
programmatically creating a table in dotnet Priya Microsoft VB .NET 3 21st Mar 2006 05:04 AM
DotNet creating user accounts John Davidson Microsoft Dot NET Framework 2 4th Jan 2004 02:02 AM
Creating a Progress Bar for Uploads in DotNet (VB.NET) Joe Finsterwald Microsoft ASP .NET 0 26th Oct 2003 07:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:47 AM.