Skip to main content
added 307 characters in body; added 41 characters in body
Source Link
mafu
  • 33k
  • 43
  • 163
  • 253

You can simply use this:

Dictionary<int, Dictionary<string, string>>

Use it like this:

var dd = new Dictionary<int, Dictionary<string, string>>();
dd[5] = new Dictionary<string, string>();
dd[5]["a"] = "foo";

You can also create a new class to simplify the creation of the inner dictionary:

class DDict { // optional: generic
    private readonly Dictionary<int, Dictionary<string, string>> _Inner = new ...;

    public Dictionary<string, string> this (int index) {
        Dictionary<string, string> d;
        if (!_Inner.TryGetValue(index, out d)) {
             d = new Dictionary<string, string>();
             _Inner.Add(index, d);
        }
        return d;
    }
}

var dd = new DDict();
dd[5]["a"] = "hi";

If the first index is sequential, you can of course also just use an array of dictionaries:

var dd = new Dictionary<string, string>[128];

Also, if the inner members are always the same, I suggest to create a new class and access it in an array:

class Dat {
    string name;
    string phone;
}
var list = new Dat[128]

// access:
list[5].name = "matt";

Instead of an array, you could also use a List or a Dictionary<int, Dat> in that case.

You can simply use this:

Dictionary<int, Dictionary<string, string>>

Use it like this:

var dd = new Dictionary<int, Dictionary<string, string>>();
dd[5] = new Dictionary<string, string>();
dd[5]["a"] = "foo";

You can also create a new class to simplify the creation of the inner dictionary:

class DDict { // optional: generic
    private readonly Dictionary<int, Dictionary<string, string>> _Inner = new ...;

    public Dictionary<string, string> this (int index) {
        Dictionary<string, string> d;
        if (!_Inner.TryGetValue(index, out d)) {
             d = new Dictionary<string, string>();
             _Inner.Add(index, d);
        }
        return d;
    }
}

var dd = new DDict();
dd[5]["a"] = "hi";

If the first index is sequential, you can of course also just use an array of dictionaries:

var dd = new Dictionary<string, string>[128];

You can simply use this:

Dictionary<int, Dictionary<string, string>>

Use it like this:

var dd = new Dictionary<int, Dictionary<string, string>>();
dd[5] = new Dictionary<string, string>();
dd[5]["a"] = "foo";

You can also create a new class to simplify the creation of the inner dictionary:

class DDict { // optional: generic
    private readonly Dictionary<int, Dictionary<string, string>> _Inner = new ...;

    public Dictionary<string, string> this (int index) {
        Dictionary<string, string> d;
        if (!_Inner.TryGetValue(index, out d)) {
             d = new Dictionary<string, string>();
             _Inner.Add(index, d);
        }
        return d;
    }
}

var dd = new DDict();
dd[5]["a"] = "hi";

If the first index is sequential, you can of course also just use an array of dictionaries:

var dd = new Dictionary<string, string>[128];

Also, if the inner members are always the same, I suggest to create a new class and access it in an array:

class Dat {
    string name;
    string phone;
}
var list = new Dat[128]

// access:
list[5].name = "matt";

Instead of an array, you could also use a List or a Dictionary<int, Dat> in that case.

added 51 characters in body; added 57 characters in body; added 150 characters in body
Source Link
mafu
  • 33k
  • 43
  • 163
  • 253

You can simply use this:

Dictionary<int, Dictionary<string, string>>

Use it like this:

var dd = new Dictionary<int, Dictionary<string, string>>();
dd[5] = new Dictionary<string, string>();
dd[5]["a"] = "foo";

You can also create a new class to simplify the creation of the inner dictionary:

class DDict { // optional: generic
    private readonly Dictionary<int, Dictionary<string, string>> _Inner = new ...; 

    public Dictionary<string, string> this (int index) {
        Dictionary<string, string> d;
        if (!_Inner.TryGetValue(index, out d)) {
             _Inner.Add(index,d = new Dictionary<string, string>();
             _Inner.Add(index, d);
        }
        return d;
    }
}

var dd = new DDict();
dd[5]["a"] = "hi";

If the first index is sequential, you can of course also just use an array of dictionaries:

var dd = new Dictionary<string, string>[128];

You can simply use this:

Dictionary<int, Dictionary<string, string>>

Use it like this:

var dd = new Dictionary<int, Dictionary<string, string>>();
dd[5] = new Dictionary<string, string>();
dd[5]["a"] = "foo";

You can also create a new class to simplify the creation of the inner dictionary:

class DDict { // optional: generic
    private readonly Dictionary<int, Dictionary<string, string>> _Inner = new ...;
    public Dictionary<string, string> this (int index) {
        Dictionary<string, string> d;
        if (!_Inner.TryGetValue(index)) {
             _Inner.Add(index, new Dictionary<string, string>());
        }
    }
}

You can simply use this:

Dictionary<int, Dictionary<string, string>>

Use it like this:

var dd = new Dictionary<int, Dictionary<string, string>>();
dd[5] = new Dictionary<string, string>();
dd[5]["a"] = "foo";

You can also create a new class to simplify the creation of the inner dictionary:

class DDict { // optional: generic
    private readonly Dictionary<int, Dictionary<string, string>> _Inner = new ...; 

    public Dictionary<string, string> this (int index) {
        Dictionary<string, string> d;
        if (!_Inner.TryGetValue(index, out d)) {
             d = new Dictionary<string, string>();
             _Inner.Add(index, d);
        }
        return d;
    }
}

var dd = new DDict();
dd[5]["a"] = "hi";

If the first index is sequential, you can of course also just use an array of dictionaries:

var dd = new Dictionary<string, string>[128];
Source Link
mafu
  • 33k
  • 43
  • 163
  • 253

You can simply use this:

Dictionary<int, Dictionary<string, string>>

Use it like this:

var dd = new Dictionary<int, Dictionary<string, string>>();
dd[5] = new Dictionary<string, string>();
dd[5]["a"] = "foo";

You can also create a new class to simplify the creation of the inner dictionary:

class DDict { // optional: generic
    private readonly Dictionary<int, Dictionary<string, string>> _Inner = new ...;
    public Dictionary<string, string> this (int index) {
        Dictionary<string, string> d;
        if (!_Inner.TryGetValue(index)) {
             _Inner.Add(index, new Dictionary<string, string>());
        }
    }
}