csharp beginner

csharp beginner

  • NA
  • 38
  • 11.9k

find max value

Oct 30 2013 7:25 AM
i need to find max value within a file. This means finding max value within each 1000 values in a file, i.e., if there is 5000 values within a file then there should be 5 max values. Within first 1000 values: one max value, then within next 1000 values one more max value.... and so on. 

# the size of the file will be unknown

# i had prepared a code for finding max value within first 1000 values in the file. I was thinking of iterating it, to get the desired results, but could not. The codes are as follows.

        List<Double> list = new List<Double>();
                StreamReader dat = new StreamReader(file path);
                //int count = 1;
                string dataline = "";
                for (int i = 1; i <= dat.BaseStream.Length; i+=1000)
                {
                    while ((dataline = dat.ReadLine()) != null)
                    {
                        Double sdat = Double.Parse(dataline);
                        list.Add(sdat);
                        richTextBox1.Text = list.Take(1000).Max().ToString();
                    }
                }
please help!
Thank you.

Answers (4)