0

現在、私はこのようなマッピング設定をしています

//Identifiers to save (currently)
Dictionary<string, Dictionary<string, string>> toSaveIdentifiers =
    new Dictionary<string, Dictionary<string, string>>(); //

ただし、追加する追加の属性を逃したため、追加のディメンションを追加したいと考えています。

プログラムで頻繁に入力され、プログラム全体でも検索される何らかの形式のマッピングを設定しようとしています。私はこれを行うための最良の方法は何だろうと思っていました。

//Identifiers to save (tuple)
Dictionary<Tuple<string,string>, Dictionary<string, string>> toSaveIdentifiers =
    new Dictionary<Tuple<string, string>, Dictionary<string, string>>(); //

//Identifiers to save (adding another dictionary dimension)
Dictionary<string, Dictionary<string,Dictionary<string, string>>> toSaveIdentifiers =
    new Dictionary<string, Dictionary<string, Dictionary<string, string>>>(); //

//Identifiers to save (adding keyvaluepair)
Dictionary<KeyValuePair<string,string>, Dictionary<string, string>> toSaveIdentifiers =
    new Dictionary<KeyValuePair<string, string>, Dictionary<string, string>>(); //

それを入力/検索すると、次のようなことをします。

   // check identifier map dictionary
    if (dictionary.Keys.Contains(identifier))
    {
        if (dictionary[identifier].Keys.Contains(currency))
        {
            //stuff
        }
        else
        {
            //stuff
        }
    }
    else
    {
            //more stuff
    }

ルックアップのためにこれを行う最良の方法は何ですか?

4

1 に答える 1

0

識別子はすべて文字列型のように見えるため、いつでもそれらすべてを 1 つの大きな文字列に連結し、それをキーとして使用できます。次に、ネストされた Contains を実行する代わりに、1 つだけ実行する必要があります。また、さまざまなレベルの識別子を保存する限り、より柔軟になります。

つまり、2 レベルのキーを指定すると、次のようになります。

string ident = level1Identifier + "." + level2Identifier;

( string.format() または StringBuilder を使用するとより効率的ですが、このコードは説明に適しています)

また、混乱や偶発的な重複を避けるために、参加するキャラクターはどのレベル識別子にも表示されないことがわかっているものにする必要があることを考慮してください。

于 2013-04-08T14:59:08.010 に答える