2012-03-26 15 views
0

これまでに単純配列を使用して、必要な情報を入力して取得しました。1つのConcurrentDictionaryで配列から値を入力して取得するC#

最初の例は以下の通りです:

  // ===Example 1. Enter info //// 
      string[] testArr1 = null; 
      testArr1[0] = "ab"; 
      testArr1[1] = "2"; 
      // ===Example 1. GET info //// 
      string teeext = testArr1[0]; 
      // ======================= 

及び第二の例:

  // ====== Example 2. Enter info //// 
      string[][] testArr2 = null; 
      List<int> listTest = new List<int>(); 
      listTest.Add(1); 
      listTest.Add(3); 
      listTest.Add(7); 
      foreach (int listitem in listTest) 
      { 
       testArr2[listitem][0] = "yohoho"; 
      } 
      // ====== Example 2. Get info //// 
      string teeext2 = testArr2[0][0]; 
      // ======================= 

しかし、今、私はにしようとしているが、各アレイへの識別番号を割り当てるので、私は可能性複数の異なる配列を1つのConcurrentDictionaryに指定します。

辞書の配列情報を入力して取得するにはどうすればよいですか?

見て、我々は2つの識別子と2つの辞書があります。それは自己だから上記のコードは動作しません(:

//////////Example 1 
//To write info 
test1.TryAdd(identifier1)[0] = "a"; 
test1.TryAdd(identifier1)[1] = "b11"; 

test1.TryAdd(identifier2)[0] = "152"; 
//to get info 
string value1 = test1.TryGetValue(identifier1)[0]; 
string value1 = test1.TryGetValue(identifier2)[0]; 

//////////Example 2 
//To write info: no idea 
//to get info: no idea 

PS:私はこのような何かを想像して

  decimal identifier1 = 254; 
      decimal identifier2 = 110; 
      ConcurrentDictionary<decimal, string[]> test1 = new ConcurrentDictionary<decimal, string[]>(); 
      ConcurrentDictionary<decimal, string[][]> test2 = new ConcurrentDictionary<decimal, string[][]>(); 

を)ConcurrentDictionaryのstring []とstring [] []に情報を入力する正しい方法は何ですか? (とそれを得るために)

+1

私は混乱しています。達成しようとしていることは何ですか? – zmbq

+0

"各配列に識別番号を割り当てようとしているので、ConcurrentDictionary内の異なる配列を識別することができます" – Alex

答えて

0

あなた宣言

decimal identifier1 = 254; 
decimal identifier2 = 110; 
ConcurrentDictionary<decimal, string[]> test1 = new ConcurrentDictionary<decimal, string[]>(); 
ConcurrentDictionary<decimal, string[][]> test2 = new ConcurrentDictionary<decimal, string[][]>(); 

を考えると、あなたのデータを入力するには、この

test1[identifier1] = new string[123]; 
    test1[identifier1][12] = "hello"; 

    test2[identifier2] = new string[10][]; 
    test2[identifier2][0] = new string[20]; 
    test2[identifier2][0][1] = "world"; 

ようなコードを使用することができます。ここでは、入力されたデータにアクセスする例を示します。

Console.WriteLine(test1[identifier1][12] + " " + test2[identifier2][0][1]); 

私が言わなければならないが、しかし、そのようなコードは、特にTEST2の場合のために、デバッグに非常に複雑かつ困難になる傾向があるということ。ギザギザの配列を使用してもよろしいですか?

+0

データをどこかに保存する必要があります。INIファイル、SQlデータベース、ConcurrentDictionaryの間で選択してください。 – Alex

関連する問題