Question: C# I have a text file that I used StreamReader to put into a listBox. Each line in the listBox is a population that has

C# I have a text file that I used StreamReader to put into a listBox. Each line in the listBox is a population that has a corresponding year. How do I

a) assign years to those lines

b) compare each line for the change in population

c) determine which lines have the greatest increase and greatest decrease

Take the increase and decrease and put into a label or text box.

Here is what I have so far:

My Form has a read and exit button and the listbox

I thought I would add a greatest increase and greatest decrease button for those click events but would still need to parse them into a label or textbox I am using Visual Studio

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 Wiseman_ITM_225_HW_6

{

public partial class Form1 : Form

{

//variables

decimal[] populatoin = new decimal[41];

public Form1()

{

InitializeComponent();

}

private void readButton_Click(object sender, EventArgs e)

{

try

{

const int SIZE = 40;

int[] population = new int[SIZE];

int index = 0;

StreamReader inputFile;

inputFile = File.OpenText("USPopulation.txt");

while (index < population.Length && !inputFile.EndOfStream)

{

population[index] = int.Parse(inputFile.ReadLine());

index++;

}

inputFile.Close();

foreach (int value in population)

{

populationListBox.Items.Add(value);

}

}

catch (Exception ex)

{

MessageBox.Show(ex.Message);

}

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!