<i id='roUi7'><tr id='roUi7'><dt id='roUi7'><q id='roUi7'><span id='roUi7'><b id='roUi7'><form id='roUi7'><ins id='roUi7'></ins><ul id='roUi7'></ul><sub id='roUi7'></sub></form><legend id='roUi7'></legend><bdo id='roUi7'><pre id='roUi7'><center id='roUi7'></center></pre></bdo></b><th id='roUi7'></th></span></q></dt></tr></i><div id='roUi7'><tfoot id='roUi7'></tfoot><dl id='roUi7'><fieldset id='roUi7'></fieldset></dl></div>

<small id='roUi7'></small><noframes id='roUi7'>

  • <tfoot id='roUi7'></tfoot>
      <bdo id='roUi7'></bdo><ul id='roUi7'></ul>
  • <legend id='roUi7'><style id='roUi7'><dir id='roUi7'><q id='roUi7'></q></dir></style></legend>

      1. 如何在列表框中找到最低、最高和平均值

        How to find the lowest, highest and average values in a listbox(如何在列表框中找到最低、最高和平均值)

          <tbody id='PoYC5'></tbody>
      2. <i id='PoYC5'><tr id='PoYC5'><dt id='PoYC5'><q id='PoYC5'><span id='PoYC5'><b id='PoYC5'><form id='PoYC5'><ins id='PoYC5'></ins><ul id='PoYC5'></ul><sub id='PoYC5'></sub></form><legend id='PoYC5'></legend><bdo id='PoYC5'><pre id='PoYC5'><center id='PoYC5'></center></pre></bdo></b><th id='PoYC5'></th></span></q></dt></tr></i><div id='PoYC5'><tfoot id='PoYC5'></tfoot><dl id='PoYC5'><fieldset id='PoYC5'></fieldset></dl></div>
        <legend id='PoYC5'><style id='PoYC5'><dir id='PoYC5'><q id='PoYC5'></q></dir></style></legend>

            <bdo id='PoYC5'></bdo><ul id='PoYC5'></ul>

              • <small id='PoYC5'></small><noframes id='PoYC5'>

                <tfoot id='PoYC5'></tfoot>
                • 本文介绍了如何在列表框中找到最低、最高和平均值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试创建一个程序来计算和显示列表框中项目的最高、最低和平均值(从 txt 文件生成的项目).我终于想出了如何将文本文件加载到列表框.我一直在寻找线索大约一个小时,我所有的尝试都把我带到了死胡同.

                  I'm trying to create a program that calculates and displays the highest, lowest and average value of items in a listbox (items generated from a txt file). I finally figured out how to load a text file to the listbox. I have been searching for clues for about an hour and all my attempts have brought me to a dead end.

                  我的列表框称为 readListbox,我的最高、最低和平均标签分别称为最高标签、最低标签和平均标签.我该如何着手创建这个程序.数字采用十进制格式.任何帮助将不胜感激.

                  my listbox is called readListbox and my Highest, Lowest and Average labels are called highestLabel, lowestLabel and averageLabel respectively. How do I go about creting this program. The numbers are in the decimal format. Any Help will be very much appreciated.

                  private void readButton_Click(object sender, EventArgs e)
                  {
                      try
                      {
                          OpenFileDialog Open = new OpenFileDialog();
                          if(Open.ShowDialog() == DialogResult.OK)
                          {
                              readListbox.Text = Open.FileName;
                              string[] lines = System.IO.File.ReadAllLines(Open.FileName);
                              readListbox.Items.AddRange(lines);
                          }
                      }
                      catch
                      {
                          MessageBox.Show("Error");
                      }
                  
                      }
                  }
                  }
                  

                  推荐答案

                  读取文件的字符串元素后,您需要将它们转换为十进制值.此时,您可以使用 IEnumerable 扩展的内置方法来获取数据

                  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);
                   }
                  

                  这篇关于如何在列表框中找到最低、最高和平均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Populate ListBox with a IEnumrable on another thread (winforms)(在另一个线程(winforms)上使用 IEnumrable 填充 ListBox)
                  listbox selected item give me quot; System.Data.DataRowViewquot; , C# winforms(列表框选择的项目给我quot;System.Data.DataRowView, C# Winforms)
                  Cannot remove items from ListBox(无法从列表框中删除项目)
                  Preventing ListBox scrolling to top when updated(更新时防止列表框滚动到顶部)
                  Drag and drop from list to canvas on windows phone with MVVM(使用 MVVM 在 Windows 手机上从列表拖放到画布)
                  Deselection on a WPF listbox with extended selection mode(具有扩展选择模式的 WPF 列表框上的取消选择)
                    <tbody id='nFQ3z'></tbody>
                  • <bdo id='nFQ3z'></bdo><ul id='nFQ3z'></ul>

                      <tfoot id='nFQ3z'></tfoot>

                      <small id='nFQ3z'></small><noframes id='nFQ3z'>

                      <legend id='nFQ3z'><style id='nFQ3z'><dir id='nFQ3z'><q id='nFQ3z'></q></dir></style></legend>
                        • <i id='nFQ3z'><tr id='nFQ3z'><dt id='nFQ3z'><q id='nFQ3z'><span id='nFQ3z'><b id='nFQ3z'><form id='nFQ3z'><ins id='nFQ3z'></ins><ul id='nFQ3z'></ul><sub id='nFQ3z'></sub></form><legend id='nFQ3z'></legend><bdo id='nFQ3z'><pre id='nFQ3z'><center id='nFQ3z'></center></pre></bdo></b><th id='nFQ3z'></th></span></q></dt></tr></i><div id='nFQ3z'><tfoot id='nFQ3z'></tfoot><dl id='nFQ3z'><fieldset id='nFQ3z'></fieldset></dl></div>