How to find the lowest, highest and average values in a listbox [closed]

ⅰ亾dé卋堺 提交于 2019-12-02 13:34:07

After reading the string elements of your file you need to convert them to decimal values. At that point you can use the built in methods of the IEnumerable extensions to get your data

OpenFileDialog Open = new OpenFileDialog();
if(Open.ShowDialog() == DialogResult.OK)
{
        readListbox.Text = Open.FileName;
        string[] lines = System.IO.File.ReadAllLines(Open.FileName);

        decimal[] values = lines.Select(x => decimal.Parse(x)).ToArray();
        labelHigh.Text = values.Max().ToString();
        labelMin.Text = values.Min().ToString();
        labelAvg.Text = values.Average().ToString();        

        readListbox.Items.AddRange(lines);
 }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!