Question

i search for a good solution for mapping data in c#.
At first i have a Character "a" and a angle "0.0" degree.
What is the best solution for the Mapping ? A list ?

One requirement is that i must search for the degree if it not in the "list" then i add a new one.. and so on

thanks for help :)

EDIT: I must find out if the angle exists ! If the angle not exists then add a new char

Was it helpful?

Solution

Dictionary< double,char>

Example:

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;   
 }

OTHER TIPS

Use dictionary.

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

Dictionary should be fine:

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;
}

Maybe a SortedDictionary.?

 private SortedDictionary<string, double> _myStuff;

...

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

Hashtable looks to be the thing you are looking for. Make the degree as the Hashkey and you can search it later quite easily.


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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top