We have answer of your question!

100% solved queries, no empty question

Question: Manipulating information stored in array


0

I have a lot of data stored in multiple arrays that I would like to get a value from but I'm having trouble. The identifier arrays are

String[] seqNum2 = new String[600];
String[] seqNum = new String[600];

I want to be able to find the match data in those arrays and get information that aligns with the data in these arrays

String[] netOil2 = new String[600];
String[] netOil = new String[600];

So here is my code so far but it is not outputting the correct answer that I want, all it is outputting is an infinite loop that says "System.String[], NaN".

    private void netOilRadBtn_CheckedChanged(object sender, EventArgs e)
    {
        StreamWriter sw = new StreamWriter("test.txt"); //testing purposes only
        //StreamReader sr = new StreamReader("OUTPUT.CSV");
        double first;
        double second;


        for (int i = 0; i < netOil2.Length; i++)
            {
                for (int j = 0; j < netOil.Length; j++)
                {
                    if (seqNum2[i] == seqNum[j])
                    {
                        //sw.WriteLine("Find New Seq Num");
                        first = Convert.ToDouble(netOil2[i]);
                        second = Convert.ToDouble(netOil[j]);

                        double answer = (first - second) / first;

                        sw.WriteLine("{0}, {1}", seqNum2, answer);
                    }
                }
            }

    }

All I want to be able to do is output the matching seqNum and then the double answer. Any help would be greatly appreciated.

Question author Stock | Source

Answer


1


private void netOilRadBtn_CheckedChanged(object sender, EventArgs e)
{
    using (var sw = new StreamWriter("test.txt")) //testing purposes only
    { 
        //StreamReader sr = new StreamReader("OUTPUT.CSV");

        var items =  netOil.Zip(seqNum, (oil, seq) => new {Oil = oil, Seq = seq});
        var items2 =  netOil2.Zip(seqNum2, (oil, seq) => new {Oil = oil, Seq = seq});

        foreach (var item in items.Join(items2,
                     i=>i.Seq,i=>i.Seq, (a,b)=>
                     {
                         double first = Convert.ToDouble(a.Oil);
                         double second = Convert.ToDouble(b.Oil);

                         double answer = (first - second) / first;
                         return string.Format("{0}, {1}", a.Seq, answer);
                     }))

        { 
            sw.WriteLine(item);
        }
    }
}
Answer author Joel-coehoorn

Tickanswer.com is providing the only single recommended solution of the question Manipulating information stored in array under the categories i.e c# , arrays , . Our team of experts filter the best solution for you.

Related Search Queries:

array processing in computer architecture , array manipulation in c ,


You may also add your answer

Thanks for contributing an answer to Tick Answer!