2009-06-19 28 views
1

我尋找一個很好的解決方案,用於在c#中映射數據。
起初我有一個字符「a」和一個角度「0.0」度。
映射的最佳解決方案是什麼?一個列表 ?c#中一些數據的映射

的一個要求是,我必須尋找程度,如果它不是在「名單」,然後我添加一個新的..等等

感謝幫助:)

編輯:我必須找出角度是否存在!如果該角度不存在,那麼添加新的炭

回答

4

字典<雙,炭>

實施例:

Dictionary< double, char> dic = new Dictionary< double, char>(); 
//Adding a new item 
void AddItem(char c, double angle) 
{ 
    if (!dic.ContainsKey(angle)) 
     dic.Add(angle,c); 
} 
//Retreiving an item 
char GetItem(double angle) 
{ 
    char c; 
    if (!dic.TryGetValue(angle, out c)) 
     return ''; 
    else 
     return c; 
} 
+0

但char,double必須是double,char – subprime 2009-06-19 07:54:16

+0

done! 。 – AlexDrenea 2009-06-19 07:56:41

+0

我怎麼能得到特定的雙重字符?和u必須修復:void AddItem(double angle,char c,Dictionary dic) – subprime 2009-06-19 08:04:49

1

使用字典。

var d =new Dictionary<string,double>()` 
-1

Hashtable看起來是你正在尋找的東西。使學位成爲哈希鍵,你可以很容易地搜索它。

 
 
Hashtable ht = new Hashtable(); 
if (!ht.ContainsKey(angle)) 
    ht.Add(key, value);

1

字典應該是罰款:

Dictionary<string, float> dict = new Dictionary<string, float>(); 
dict.Add("a", 0.0); 
float angle = dict["a"] 
if(!dict.Contains("b")) 
{ 
    dict["b"] = 1.0; 
} 
0

也許SortedDictionary

private SortedDictionary<string, double> _myStuff; 

... 

if (!_myStuff.ContainsValue(0)) 
...