2017-03-02 5 views
-4

辞書から値を呼び出したときにこのエラーが発生しましたが、エラーは表示されません。 私のターゲットは辞書からの値を持つインデックスを取得します。同じキーを持つ項目がすでに追加されています - 辞書呼び出しの値c#

どのような解決策ですか?

私のエラー:

An item with the same key has already been added.

私dictionaryclass私は

if (tmp.PMC_UM == "") 
      { 
       string valore = String.Empty; 
       //devo prendere la x ed estrarla dal dizionario per stampare le stringhe 
       #region VERIFICO LE STRINGHE E LE PRELEVO DAI DICTIONARY 
       if (tmp.PMC_Descrizione == "Language") 
       { 
        valore = DictionaryParamiters.languagesDictionary[(int)x]; 
       } 

       if (tmp.PMC_Descrizione == "Model" && DataFile.instance.PMC_SUB_Tipo_Click == null) 
       { 
        valore = DictionaryParamiters.modelDictionary[(int)x]; 
       } 

       //if (tmp.PMC_Descrizione == "Model" && DataFile.instance.PMC_SUB_Tipo_Click != null) 
       //{ 
       // valore = DictionaryParamiters.modelMMGOPLUSDictionary[(int)x]; 
       //} 

       if (tmp.PMC_Descrizione == "Rst Cnthr"/* || tmp.PMC_Descrizione == "Rst Main Cnthr" || tmp.PMC_Descrizione == "Side brush" || tmp.PMC_Descrizione == "Daylight Enable" || tmp.PMC_Descrizione == "Daylight Enable" || tmp.PMC_Descrizione == "Worklight Enable " || tmp.PMC_Descrizione == "Dosing system" || tmp.PMC_Descrizione == "Recycle" || tmp.PMC_Descrizione == "Anticollision" || tmp.PMC_Descrizione == "Rear camera" || tmp.PMC_Descrizione == "Manual Op. Enable" || tmp.PMC_Descrizione == "Zone Op. Enable" || tmp.PMC_Descrizione == "Password Enable: User" || tmp.PMC_Descrizione == "Password Enable: PIN"*/) 
       { 
        valore = DictionaryParamiters.noyesDictionary[(int)x]; 
       } 

       if (tmp.PMC_Descrizione == "Battery") 
       { 
        valore = DictionaryParamiters.batteryDictionary[(int)x]; 
       } 

       if (tmp.PMC_Descrizione == "Battery Type") 
       { 
        valore = DictionaryParamiters.batteryMMGDictionary[(int)x]; 
       } 

       if (tmp.PMC_Descrizione == "Display Cnt") 
       { 
        valore = DictionaryParamiters.displayCntDictionary[(int)x]; 
       } 

       if (tmp.PMC_Descrizione == "Base version") 
       { 
        valore = DictionaryParamiters.baseversionDictionary[(int)x]; 
       } 

       if (tmp.PMC_Descrizione == "Partial Hurmeter display") 
       { 
        valore = DictionaryParamiters.partialHurmeterdisplayDictionary[(int)x]; 
       } 

       if (tmp.PMC_Descrizione == "Reset Partial Hourmeter") 
       { 
        valore = DictionaryParamiters.resetPartialHourmeterDictionary[(int)x]; 
       } 

       if (tmp.PMC_Descrizione == "Reset Main Hourmeter") 
       { 
        valore = DictionaryParamiters.resetMainHourmeterDictionary[(int)x]; 
       } 

       if (tmp.PMC_Descrizione == "Service Warning Count") 
       { 
        valore = DictionaryParamiters.serviceWarningCountDictionary[(int)x]; 
       } 
       #endregion 

       par.ValoreSettatoOra = valore; 
      } 

が重複する値を見つけるi'dont呼び出す

public static class DictionaryParamiters 
{ 
    public static Dictionary<int, String> languagesDictionary = new Dictionary<int, String> 
    { 
     { 0, "ITA" }, 
     { 1, "ENG" }, 
     { 2, "FRA" }, 
     { 3, "SPA" }, 
     { 4, "DEU" } 
    }; 

    public static Dictionary<int, String> modelDictionary = new Dictionary<int, String> 
    { 
     { 0, "IMX BT" }, 
     { 1, "IMX B" }, 
     { 2, "MMX BT" }, 
     { 3, "MMX B" }, 
     { 4, "IMX BT (no logo)" }, 
     { 5, "IMX B (no logo)" } 
    }; 

    public static Dictionary<int, String> batteryDictionary = new Dictionary<int, String> 
    { 
     { 0, "GEL" }, 
     { 1, "WET" }, 
     { 2, "XFC" }, 
     { 3, "GEL1" }, 
     { 4, "WET1" } 
    }; 

    public static Dictionary<int, String> batteryMMGDictionary = new Dictionary<int, String> 
    { 
     { 0, "PB" }, 
     { 1, "GEL" }, 
     { 2, "XFC" }, 
     { 3, "PB1" }, 
     { 4, "GEL1" }, 
     { 5, "CUSTOM" } 
    }; 

    public static Dictionary<int, String> partialHurmeterdisplayDictionary = new Dictionary<int, String> 
    { 
     { 0, "KEY" }, 
     { 1, "TR" }, 
     { 2, "BR" }, 
     { 3, "VAC" } 
    }; 

    public static Dictionary<int, String> resetPartialHourmeterDictionary = new Dictionary<int, String> 
    { 
     { 0, "NO" }, 
     { 1, "KEY" }, 
     { 2, "TR" }, 
     { 3, "BR" }, 
     { 3, "VAC" }, 
     { 3, "ALL" } 
    }; 

    public static Dictionary<int, String> resetMainHourmeterDictionary = new Dictionary<int, String> 
    { 
     { 0, "NO" }, 
     { 1, "KEY" }, 
     { 2, "TR" }, 
     { 3, "BR" }, 
     { 3, "VAC" }, 
     { 3, "ALL" } 
    }; 

    public static Dictionary<int, String> serviceWarningCountDictionary = new Dictionary<int, String> 
    { 
     { 0, "KEY" }, 
     { 1, "TR" }, 
     { 2, "WORK" } 
    };   

    public static Dictionary<int, String> noyesDictionary = new Dictionary<int, String> 
    { 
     { 0, "NO" }, 
     { 1, "YES" } 
    }; 

    public static Dictionary<int, String> displayCntDictionary = new Dictionary<int, String> 
    { 
     { 0, "KEY" }, 
     { 1, "TRACTION" } 
    }; 

    public static Dictionary<int, String> zerooneDictionary = new Dictionary<int, String> 
    { 
     { 0, "0" }, 
     { 1, "1" } 
    }; 

    public static Dictionary<int, String> baseversionDictionary = new Dictionary<int, String> 
    { 
     { 0, "RULLO" }, 
     { 1, "DISCO" }, 
     { 2, "ORBITALE" } 
    }; 

    public static Dictionary<int, String> modelMMGOPLUSDictionary = new Dictionary<int, String> 
    { 
     { 0, "MMG" }, 
     { 1, "PLUS" } 
    }; 
} 

...あなたは:(

+4

あなたの 'resetPartialHourmeterDictionary'と' resetMainHourmeterDictionary'には重複したキーがあります。 – Zroq

+0

6番目と7番目の辞書には、キー "3"が複数回 – pinkfloydx33

+0

ですが、辞書の名前は2つあります。 –

答えて

1

キー値3を挿入する複数回。ディクショナリでは、各キーは一意でなければなりません。あなたのresetPartialHourmeterDictionaryresetMainHourmeterDictionary

public static Dictionary<int, String> resetPartialHourmeterDictionary = new Dictionary<int, String> 
    { 
     { 0, "NO" }, 
     { 1, "KEY" }, 
     { 2, "TR" }, 
     { 3, "BR" }, 
     { 3, "VAC" }, 
     { 3, "ALL" } 
    }; 
+0

エラーがあります –

0

、あなたはそこに同じキー3を持っています。

関連する問題