# 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
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.
please help!
Thank you.
VulpesPosted Oct 30, 2013, 2:58 PM
string[] datalines = File.ReadAllLines(filepath);
int thousands = datalines.Length / 1000;
int remainder = datalines.Length % 1000;
string temp = "";
for(int i = 0; i < thousands; i++)
{
temp += datalines.Select(s => double.Parse(s))
.Skip(i * 1000).Take(1000).Max().ToString() + "\r\n";
}
if (remainder > 0)
{
temp += datalines.Select(s => double.Parse(s))
.Skip(thousands * 1000).Take(remainder).Max().ToString();
}
richTextBox1.Text = temp;
csharp beginnerPosted Oct 31, 2013, 12:59 AM
you are awesome. Thank you.
csharp beginnerPosted Oct 30, 2013, 10:57 AM
VulpesPosted Oct 30, 2013, 8:25 AM
richTextBox1.Text = list.Skip(1000).Take(1000).Max().ToString();
gets the maximum value of the elements 1001 to 2000 in the list.