M
Michael Bray
Lets say I want to have a sparse lookup by two int values to a string
value... I can do it by:
Dictionary<int, Dictionary<int, string>> d = new ...
d[4953][1344] = "hello";
This is fine if there is only two levels... but I have a situation where
I want to declare one with more levels, lets just say for the sake of the
discussion that I need 4 levels... Using the above, I would have to do:
D<int, D<int, D<int, D<int, string>>>> d = new ...
d[2938][2375][9284378][123491] = "4 levels";
(I write D<...> instead of Dictionary for formatting.)
Obviously this can get pretty unwieldly. If I only had to declare it once
then it wouldn't be a big deal... But when I want to start writing
functions that pass these structures around, it just feels crazy to do it
this way:
public void MyFunc(
D<int, D<int, D<int, D<int, string>>>> input,
D<int, D<int, D<int, D<int, string>>>> map,
D<int, D<int, D<int, D<int, string>>>> output );
In C++, I could do a typedef to declare it once and then just refer to it
by the typedef name... I don't think anything similar in C# exists, but
I'm hopeful. The #define statement obviously doesn't do what I need it to
either.
Any suggestions?
-mdb
value... I can do it by:
Dictionary<int, Dictionary<int, string>> d = new ...
d[4953][1344] = "hello";
This is fine if there is only two levels... but I have a situation where
I want to declare one with more levels, lets just say for the sake of the
discussion that I need 4 levels... Using the above, I would have to do:
D<int, D<int, D<int, D<int, string>>>> d = new ...
d[2938][2375][9284378][123491] = "4 levels";
(I write D<...> instead of Dictionary for formatting.)
Obviously this can get pretty unwieldly. If I only had to declare it once
then it wouldn't be a big deal... But when I want to start writing
functions that pass these structures around, it just feels crazy to do it
this way:
public void MyFunc(
D<int, D<int, D<int, D<int, string>>>> input,
D<int, D<int, D<int, D<int, string>>>> map,
D<int, D<int, D<int, D<int, string>>>> output );
In C++, I could do a typedef to declare it once and then just refer to it
by the typedef name... I don't think anything similar in C# exists, but
I'm hopeful. The #define statement obviously doesn't do what I need it to
either.
Any suggestions?
-mdb