473,396 Members | 1,900 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,396 software developers and data experts.

Dictionary of dictionaries

I’m looking for a way to create a generic dictionary of generic dictionaries
grouped by type. Something like this

Class the Grouping ChildItem<T>{…}

Class ParentGrouping {
Dictionary<Type, ChildItem <theGrouppingItemtype>> myDimDict;
}

So I would access it like this

ParentGrouping[System.string, “myitemKey”] = “new value”;
OR
ParentGrouping[System.Drawing.Point, “myitemKey”] = new
System.Drawing.Point(0,0);

Any ideas?



Mar 20 '06 #1
2 17024
> So I would access it like this
ParentGrouping[System.string, "myitemKey"] = "new value";
OR
ParentGrouping[System.Drawing.Point, "myitemKey"] = new
System.Drawing.Point(0,0);

You can do something like this.

Dictionary<string, MyClass> myclass = new Dictionary<string,
MyClass>();
myclass.Add("one", new MyClass(new System.Drawing.Point(1, 2)));
myclass.Add("two", new MyClass("Hello"));
The complete example (a console app):

using System;
using System.Collections.Generic;
using System.Text;

namespace Generics_Dictionary
{

class MyClass
{
private System.Drawing.Point _point = new System.Drawing.Point();
private string _MyText = "";
private bool EmptyText = true;

public MyClass(System.Drawing.Point point)
{
_point = point;
}

public MyClass(string MyText)
{
this.EmptyText = false;
this._MyText = MyText;
}

public string MyText
{
get
{
return this._MyText;
}
set
{
this.EmptyText = false;
this._MyText = value;
}
}

public System.Drawing.Point MyPoint
{
get
{
return this._point;
}
set
{
this._point = value;
}
}

public bool IsTextEmpty
{
get
{
return this.EmptyText;
}
}
}
class Program
{
public Program()
{
Dictionary<string, MyClass> myclass = new Dictionary<string,
MyClass>();
myclass.Add("one", new MyClass(new System.Drawing.Point(1, 2)));
myclass.Add("two", new MyClass("Hello"));

foreach (KeyValuePair<string, MyClass> cls in myclass)
{

if (!cls.Value.MyPoint.IsEmpty)
System.Console.WriteLine("Text : " + cls.Value.MyPoint.X
+ "." + cls.Value.MyPoint.Y);
if (!cls.Value.IsTextEmpty)
System.Console.WriteLine("Text : " + cls.Value.MyText);

}
System.Console.ReadKey();
}

static void Main(string[] args)
{
new Program();
}
}
}

Regards,
Lars-Inge Tnnessen
Mar 20 '06 #2
First, thanks for taking the time to respond.
The crux of my problem resides in the fact that your version of MyClass is
not a strongly typed class.
MyClass<T> would be what I’m looking for. Reason is that the types to be
stored in each list is not limited to string and point.
That’s why I wanted to tie the T for MyClass<T> to the key of types in the
parent Dictionary.
"AdamH" wrote:
I’m looking for a way to create a generic dictionary of generic dictionaries
grouped by type. Something like this

Class the Grouping ChildItem<T>{…}

Class ParentGrouping {
Dictionary<Type, ChildItem <theGrouppingItemtype>> myDimDict;
}

So I would access it like this

ParentGrouping[System.string, “myitemKey”] = “new value”;
OR
ParentGrouping[System.Drawing.Point, “myitemKey”] = new
System.Drawing.Point(0,0);

Any ideas?


Mar 20 '06 #3

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

Similar topics

2
by: John Mudd | last post by:
I must be missing something here. It's clearly faster to lookup an item directly in a dictionary than to scan through a list. So when I have a large lookup table I always load it in the form of a...
4
by: Vibha Tripathi | last post by:
Hi Folks, I know sets have been implemented using dictionary but I absolutely need to have a set of dictionaries...any ideas how to do that? Peace. Vibha "Things are only impossible until...
5
by: Fox | last post by:
Hi, I am working on a project which used dictionaries. I am having to remake part of this and have no experience with the scripting dictionary. I need to see how to create multiple...
90
by: Christoph Zwerschke | last post by:
Ok, the answer is easy: For historical reasons - built-in sets exist only since Python 2.4. Anyway, I was thinking about whether it would be possible and desirable to change the old behavior in...
70
by: jojoba | last post by:
Hello! Does anyone know how to find the name of a python data type. Conside a dictionary: Banana = {} Then, how do i ask python for a string representing the name of the above dictionary...
3
by: Rich Shepard | last post by:
I need to learn how to process a byte stream from a form reader where each pair of bytes has meaning according to lookup dictionaries, then use the values to build an array of rows inserted into a...
8
by: akameswaran | last post by:
I wrote up a quick little set of tests, I was acutally comparing ways of doing "case" behavior just to get some performance information. Now two of my test cases had almost identical results which...
8
by: Brian L. Troutwine | last post by:
I've got a problem that I can't seem to get my head around and hoped somebody might help me out a bit: I've got a dictionary, A, that is arbitarily large and may contains ints, None and more...
11
by: John | last post by:
I am coding a radix sort in python and I think that Python's dictionary may be a choice for bucket. The only problem is that dictionary is a mapping without order. But I just found that if the...
4
by: =?utf-8?B?TWFjaWVqIEJsaXppxYRza2k=?= | last post by:
Hi Pythonistas! I've got a question about storing tuples in a dictionary. First, a small test case which creates a list of dictionaries: import time list_of_dicts = keys = prev_clk =...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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...
0
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...

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.