473,549 Members | 2,726 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

generics question

I need a generic collection that will do the following

key/value/value

or

index/value/value

basically I need a multidimensiona l generic Collection if that is even
possible!

Thanks!
Mar 13 '06 #1
7 4478
Generally, I would expect a multi-dimensional collection to be
multi-dimensional on the /key/, not the /value/, i.e. key/key/value;

however, if you need key/value/value, you could either create a class to
represent your value/value pair, and then use key/YourNewWrapper, else (if
the dimenstion is indeterminate) use something like key/value[], i.e. each
key returns an array of values (substitute array for any other collection).

For key/key/value, you can create e.g. Dictionary<stri ng, Dictionary<int,
DateTime>>, which for each string (key) will return a dictionary
(intermediate value), and each int (key) in that (child dictionary) will
return a DateTime (leaf value) (types chosen here to illustrate the point).

So - how exactly do you want it to behave?

Marc

"Sean" <Se**@discussio ns.microsoft.co m> wrote in message
news:91******** *************** ***********@mic rosoft.com...
I need a generic collection that will do the following

key/value/value

or

index/value/value

basically I need a multidimensiona l generic Collection if that is even
possible!

Thanks!

Mar 13 '06 #2
Sean,

Use a Dictionary<K, V> instance. Create a type that exposes the
value/value pair (through fields/properties) and use that as the value type.

Then, for the key, just use your key.

Are you sure that you need to use an index? What are you using it for?
I've found that when people use a dictionary, they have little need for an
index, and can get around it using another dictionary (mapping index to
key), or through the Keys collection exposed by the dictionary.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Sean" <Se**@discussio ns.microsoft.co m> wrote in message
news:91******** *************** ***********@mic rosoft.com...
I need a generic collection that will do the following

key/value/value

or

index/value/value

basically I need a multidimensiona l generic Collection if that is even
possible!

Thanks!

Mar 13 '06 #3
Although I said "key" its true I really dont need a key.

What I am looking for is a generic "collection s of collections" which is a
specific phrase I read somewhere and I cant seem to find it again!

true about not needing keys. We have some of that in our code right now.
SortList<T> is being used to sort a list however the list is then populated
in a datagrid! Well I thought the grids already had IList (or whatever
interface) required for sorting.

Never the less, in general I am looking for either a collection of
collections or a generic multidimensiona l "List".

Thanks for your help

"Nicholas Paldino [.NET/C# MVP]" wrote:
Sean,

Use a Dictionary<K, V> instance. Create a type that exposes the
value/value pair (through fields/properties) and use that as the value type.

Then, for the key, just use your key.

Are you sure that you need to use an index? What are you using it for?
I've found that when people use a dictionary, they have little need for an
index, and can get around it using another dictionary (mapping index to
key), or through the Keys collection exposed by the dictionary.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Sean" <Se**@discussio ns.microsoft.co m> wrote in message
news:91******** *************** ***********@mic rosoft.com...
I need a generic collection that will do the following

key/value/value

or

index/value/value

basically I need a multidimensiona l generic Collection if that is even
possible!

Thanks!


Mar 15 '06 #4
public class CollectionColle ction: Collection<Coll ectionType>
{
}

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer

Presuming that God is "only an idea" -
Ideas exist.
Therefore, God exists.

"Sean" <Se**@discussio ns.microsoft.co m> wrote in message
news:C2******** *************** ***********@mic rosoft.com...
Although I said "key" its true I really dont need a key.

What I am looking for is a generic "collection s of collections" which is a
specific phrase I read somewhere and I cant seem to find it again!

true about not needing keys. We have some of that in our code right now.
SortList<T> is being used to sort a list however the list is then
populated
in a datagrid! Well I thought the grids already had IList (or whatever
interface) required for sorting.

Never the less, in general I am looking for either a collection of
collections or a generic multidimensiona l "List".

Thanks for your help

"Nicholas Paldino [.NET/C# MVP]" wrote:
Sean,

Use a Dictionary<K, V> instance. Create a type that exposes the
value/value pair (through fields/properties) and use that as the value
type.

Then, for the key, just use your key.

Are you sure that you need to use an index? What are you using it
for?
I've found that when people use a dictionary, they have little need for
an
index, and can get around it using another dictionary (mapping index to
key), or through the Keys collection exposed by the dictionary.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Sean" <Se**@discussio ns.microsoft.co m> wrote in message
news:91******** *************** ***********@mic rosoft.com...
>I need a generic collection that will do the following
>
> key/value/value
>
> or
>
> index/value/value
>
> basically I need a multidimensiona l generic Collection if that is even
> possible!
>
> Thanks!


Mar 16 '06 #5
I wish I could do the following

dim example as List(of String)(of String)

example.add("so mething")("some thing else")

"Kevin Spencer" wrote:
public class CollectionColle ction: Collection<Coll ectionType>
{
}

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer

Presuming that God is "only an idea" -
Ideas exist.
Therefore, God exists.

"Sean" <Se**@discussio ns.microsoft.co m> wrote in message
news:C2******** *************** ***********@mic rosoft.com...
Although I said "key" its true I really dont need a key.

What I am looking for is a generic "collection s of collections" which is a
specific phrase I read somewhere and I cant seem to find it again!

true about not needing keys. We have some of that in our code right now.
SortList<T> is being used to sort a list however the list is then
populated
in a datagrid! Well I thought the grids already had IList (or whatever
interface) required for sorting.

Never the less, in general I am looking for either a collection of
collections or a generic multidimensiona l "List".

Thanks for your help

"Nicholas Paldino [.NET/C# MVP]" wrote:
Sean,

Use a Dictionary<K, V> instance. Create a type that exposes the
value/value pair (through fields/properties) and use that as the value
type.

Then, for the key, just use your key.

Are you sure that you need to use an index? What are you using it
for?
I've found that when people use a dictionary, they have little need for
an
index, and can get around it using another dictionary (mapping index to
key), or through the Keys collection exposed by the dictionary.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Sean" <Se**@discussio ns.microsoft.co m> wrote in message
news:91******** *************** ***********@mic rosoft.com...
>I need a generic collection that will do the following
>
> key/value/value
>
> or
>
> index/value/value
>
> basically I need a multidimensiona l generic Collection if that is even
> possible!
>
> Thanks!


Mar 21 '06 #6
here is what hit me as my solution

Dim returnColumns As New List(Of String())
returnColumns.A dd(New String(1) {"Order", "String"})
returnColumns.A dd(New String(1) {"Task Name", "String"))

"Kevin Spencer" wrote:
public class CollectionColle ction: Collection<Coll ectionType>
{
}

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer

Presuming that God is "only an idea" -
Ideas exist.
Therefore, God exists.

"Sean" <Se**@discussio ns.microsoft.co m> wrote in message
news:C2******** *************** ***********@mic rosoft.com...
Although I said "key" its true I really dont need a key.

What I am looking for is a generic "collection s of collections" which is a
specific phrase I read somewhere and I cant seem to find it again!

true about not needing keys. We have some of that in our code right now.
SortList<T> is being used to sort a list however the list is then
populated
in a datagrid! Well I thought the grids already had IList (or whatever
interface) required for sorting.

Never the less, in general I am looking for either a collection of
collections or a generic multidimensiona l "List".

Thanks for your help

"Nicholas Paldino [.NET/C# MVP]" wrote:
Sean,

Use a Dictionary<K, V> instance. Create a type that exposes the
value/value pair (through fields/properties) and use that as the value
type.

Then, for the key, just use your key.

Are you sure that you need to use an index? What are you using it
for?
I've found that when people use a dictionary, they have little need for
an
index, and can get around it using another dictionary (mapping index to
key), or through the Keys collection exposed by the dictionary.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Sean" <Se**@discussio ns.microsoft.co m> wrote in message
news:91******** *************** ***********@mic rosoft.com...
>I need a generic collection that will do the following
>
> key/value/value
>
> or
>
> index/value/value
>
> basically I need a multidimensiona l generic Collection if that is even
> possible!
>
> Thanks!


Mar 21 '06 #7
Sean,
PMFJI

| dim example as List(of String)(of String)

I would expect either:

Dim example As List(Of List(Of String))

List<List<Strin g>> example;

Which is a list of a list of strings.

or

Dim example As List(Of String, String)

List<String, String> example

Which is a two dimensional list, which currently doesn't exist.

| example.add("so mething")("some thing else")

What are you expecting? Are you thinking:

Dim example As New Dictionary(Of String, List(Of String))

Dictionary<Stri ng, List<String>> example;

Then:
example.Add("so mething", New List(Of String))
example("someth ing").Add("some thing else")

example.Add("so mething", new List<String>)
example["something"].Add("something else")

If you're looking for the second, I would consider creating a new Type that
encapsulated the logic, aka a generic NameValueCollec tion.


--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Sean" <Se**@discussio ns.microsoft.co m> wrote in message
news:6A******** *************** ***********@mic rosoft.com...
|I wish I could do the following
|
| dim example as List(of String)(of String)
|
| example.add("so mething")("some thing else")
|
|
|
| "Kevin Spencer" wrote:
|
| > public class CollectionColle ction: Collection<Coll ectionType>
| > {
| > }
| >
| > --
| > HTH,
| >
| > Kevin Spencer
| > Microsoft MVP
| > ..Net Developer
| >
| > Presuming that God is "only an idea" -
| > Ideas exist.
| > Therefore, God exists.
| >
| > "Sean" <Se**@discussio ns.microsoft.co m> wrote in message
| > news:C2******** *************** ***********@mic rosoft.com...
| > > Although I said "key" its true I really dont need a key.
| > >
| > > What I am looking for is a generic "collection s of collections" which
is a
| > > specific phrase I read somewhere and I cant seem to find it again!
| > >
| > > true about not needing keys. We have some of that in our code right
now.
| > > SortList<T> is being used to sort a list however the list is then
| > > populated
| > > in a datagrid! Well I thought the grids already had IList (or whatever
| > > interface) required for sorting.
| > >
| > > Never the less, in general I am looking for either a collection of
| > > collections or a generic multidimensiona l "List".
| > >
| > > Thanks for your help
| > >
| > > "Nicholas Paldino [.NET/C# MVP]" wrote:
| > >
| > >> Sean,
| > >>
| > >> Use a Dictionary<K, V> instance. Create a type that exposes the
| > >> value/value pair (through fields/properties) and use that as the
value
| > >> type.
| > >>
| > >> Then, for the key, just use your key.
| > >>
| > >> Are you sure that you need to use an index? What are you using
it
| > >> for?
| > >> I've found that when people use a dictionary, they have little need
for
| > >> an
| > >> index, and can get around it using another dictionary (mapping index
to
| > >> key), or through the Keys collection exposed by the dictionary.
| > >>
| > >> Hope this helps.
| > >>
| > >>
| > >> --
| > >> - Nicholas Paldino [.NET/C# MVP]
| > >> - mv*@spam.guard. caspershouse.co m
| > >>
| > >> "Sean" <Se**@discussio ns.microsoft.co m> wrote in message
| > >> news:91******** *************** ***********@mic rosoft.com...
| > >> >I need a generic collection that will do the following
| > >> >
| > >> > key/value/value
| > >> >
| > >> > or
| > >> >
| > >> > index/value/value
| > >> >
| > >> > basically I need a multidimensiona l generic Collection if that is
even
| > >> > possible!
| > >> >
| > >> > Thanks!
| > >>
| > >>
| > >>
| >
| >
| >
Mar 26 '06 #8

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

Similar topics

3
1287
by: Fred | last post by:
Is there a way to use generics with vs.net 2003?? I was searching around and I saw gyro but does it works with vs.net 2003?? if it does how am I suppouse to install it. If it doesnt is there any other tool that let me?? Searching I found http://www.ericjsmith.net/codesmith/ but it works only for asp.net. Any ideas??
27
2445
by: Bernardo Heynemann | last post by:
How can I use Generics? How can I use C# 2.0? I already have VS.NET 2003 Enterprise Edition and still can´t use generics... I´m trying to make a generic collection myCollection<vartype> and still no can do... Any info would be great!
12
2724
by: Michael S | last post by:
Why do people spend so much time writing complex generic types? for fun? to learn? for use? I think of generics like I do about operator overloading. Great to have as a language-feature, as it defines the language more completely. Great to use.
13
1675
by: Luc Vaillant | last post by:
I try to compare to values of generic value type T in a generic class as follow: public class C<T> where T : struct { private T value1; private T value2; C(T value1, T value2) {
1
1881
by: Peter Kirk | last post by:
Hi I have never used generics before, and I was wondering if the following sort of use was acceptable/normal for a method: public IList<IPerson> GetPersons() { IList<IPerson> personList = new List<IPerson>(); ... // get the persons return personList;
18
2620
by: riftimes | last post by:
Hello, would you help me to find totorials with examples about generics and Dictionary thank you.
11
2462
by: hammad.awan_nospam | last post by:
Hello, I'm wondering if it's possible to do the following with Generics: Let's say I have a generic member variable as part of a generic class like this: List<DLinqQuery<TDataContext>> _queries; where DLinqQuery is a generic class that takes a type parameter
1
1667
by: Kevin S. Goff | last post by:
Hi, all, Hopefully this will make sense: I have 2 classes that implement the same generic interface. public interface IAgingReport<T> { T GetAgingReport(DateTime dAsOfDate); }
7
3243
by: SpotNet | last post by:
Hello NewsGroup, Reading up on Generics in the .NET Framework 2.0 using C# 2005 (SP1), I have a question on the application of Generics. Knowingly, Generic classes are contained in the System.Collections.Generic namespace. Literature I have read on this ties generics in with collections, hence articulate their examples as such. That's fine,...
13
3801
by: rkausch | last post by:
Hello everyone, I'm writing because I'm frustrated with the implementation of C#'s generics, and need a workaround. I come from a Java background, and am currently writing a portion of an application that needs implementations in both Java and C#. I have the Java side done, and it works fantastic, and the C# side is nearly there. The...
0
7720
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7960
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7475
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7812
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6048
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3483
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1944
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 we have to send another system
1
1061
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
766
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.