到目前爲止,我正在使用簡單數組來輸入並獲取必要的信息。輸入並從一個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];
// =======================
但現在我想分配一個標識號每個數組,所以我可以在一個ConcurrentDictionary中標識多個不同的數組。
如何在字典中輸入和獲取信息數組?
看,我們有兩個標識符和兩點字典:
decimal identifier1 = 254;
decimal identifier2 = 110;
ConcurrentDictionary<decimal, string[]> test1 = new ConcurrentDictionary<decimal, string[]>();
ConcurrentDictionary<decimal, string[][]> test2 = new ConcurrentDictionary<decimal, string[][]>();
我想象這樣的事情:
//////////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:上面的代碼不工作(因爲它是自made)..那麼什麼是通過一個ID在ConcurrentDictionary中向string []和string [] []輸入信息的正確方法? (並且把它弄出來)
我很困惑。你試圖達到什麼目標? – zmbq 2012-03-26 20:34:39
「我試圖給每個數組分配一個標識號,所以我可以在ConcurrentDictionary中標識不同的數組」 – Alex 2012-03-27 07:55:15