Question
I want to change foreach loop to for loop, two codes are in bold using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using
I want to change foreach loop to for loop, two codes are in bold
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO;
namespace Test_Score_List { public partial class Form1 : Form { public Form1() { InitializeComponent(); } // The ReadScores method reads the scores from the // TestScores.txt file into the scoresList parameter. private void ReadScores(List
while (!inputFile.EndOfStream) { scoresList.Add(int.Parse(inputFile.ReadLine())); } // Close the file. inputFile.Close(); } catch (Exception ex) { // Display an error message. MessageBox.Show(ex.Message); } }
// The DisplayScores method displays the contents of the // scoresList parameter in the ListBox control. private void DisplayScores(List
foreach (int score in scoresList) {
testScoresListBox.Items.Add(score); }
} // The Average method returns the average of the values // in the scoresList parameter. private double Average(List
} } // Return the number of aboveaverage scores. return numAbove; } // The BelowAverage method returns the number of // below average scores in scoresList private int BelowAverage(List
private void getScoresButton_Click(object sender, EventArgs e) { double averageScore; // To hold the average score int numAboveAverage; // Number of above average scores int numBelowAverage; // Number of below average scores // Create a List to hold the scores. List
private void exitButton_Click(object sender, EventArgs e) { // Close the form. this.Close(); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started