D
D
des1roer2015-11-30 09:42:35
C++ / C#
des1roer, 2015-11-30 09:42:35

C# associative arrays?

I get suppose such data

_
           id name value
           1  name    1
           2  name    2
           3  name2  NaN
           4  name2  NaN
           5  name3  10

            var NonValueArray = new Dictionary<string, double>();

            for (int i = 0, cnt = c.Count; i < cnt; i++)
            {
                logger.Trace(c[i].id + " " + c[i].value + " " + c[i].server);
                if (Double.IsNaN((c[i].value)))
                {
                    NonValueArray.Add(c[i].service, c[i].id);
                }
            }
            foreach (var pair in NonValueArray)
            {
                Console.WriteLine(pair.Key + " = " + pair.Value);
            }

get
An element with the same key has already been added.

i want to get an array of all names where the value is NaN. if you go over the list and do it. add then I get duplicates. how to get a set of unique names

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
des1roer, 2015-11-30
@des1roer

var NonValueArray = new Dictionary<string, double>();

            for (int i = 0, cnt = c.Count; i < cnt; i++)
            {
                logger.Trace(c[i].id + " " + c[i].value + " " + c[i].server);
                if (Double.IsNaN((c[i].value)))
                {
                    //NonValueArray.Add(c[i].service, c[i].id);
                    NonValueArray[c[i].service] = c[i].id;
                }
            }
            foreach (var pair in NonValueArray)
            {
                Console.WriteLine(pair.Key);
            }

D
Dmitry Makarov, 2015-11-30
@DmitryITWorksMakarov

Is it necessary to store?

public class Id: UInt32{}
public class Name: string{}
public class Value: double{}
 
public class IdNameValue
{
    public Id id{get;set;}
    public Name name {get; set;}
    public Value value {get; set;}
}

IEnumerable<IdNameValue> idNameValues = Create();

var idNameValuesWhereValueIsNaN = idNameValues.Where(item=>double.IsNaN(item.value));

A
AtomKrieg, 2015-11-30
@AtomKrieg

In the loop, fill in the names of the "set" type container (sorted set, hash set). They do not duplicate the data and do not display errors if the data is already there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question