1

My C# project is a Windows form.

I have three text files containing exam scores for separate class sections in my bin/debug folder.

This is the part I really need help with: I need to store the files in a three row jagged array divided by section .


Lastly, using the jagged array, I need to display each of these calculations in text boxes:

The average score for each individual section

The average score for all sections

The highest score of all sections

The lowest score of all sections.


Section1.txt:

 87
 93
 72
 98
 65
 70
 89
 78
 77
 66
 92
 72

Section2.txt:

 71
 98
 93
 79
 84
 90
 88
 91

Section3.txt:

 88
 81
 56
 72
 69
 74
 80
 66
 71
 73
Jaruto
  • 13
  • 6
  • I think you should first to store file path to array and read file data by array looping. – lwin Apr 29 '17 at 17:54
  • @Jze I really just need help formatting the array. – Jaruto Apr 29 '17 at 17:59
  • Yeah, i also need someone who codes my stuff for me whenever it gets a little difficult for me. Big problem, i tell you... No, seriously, what have you tried so far? (Remember people here gladly help you in your coding endeavors, but they generally don't like to code for you...) –  Apr 29 '17 at 18:08
  • @elgonzo I have got them into a jagged array I just can't figure out how to format the array into three rows. I only put all of the info down in case it would be needed. – Jaruto Apr 29 '17 at 18:12
  • 1
    Sorry, it is very unclear what you want. You talk about rows? What rows? Of what? I get you tagged your question with "WinForms". But what exactly are you talking about if you say "format the array" and mention "rows"? Show the code you have done so far with regard to the "formatting the arrays into rows"... –  Apr 29 '17 at 18:16
  • @elgonzo The three text files with scores need to be in a three row jagged array divided by their sections. – Jaruto Apr 29 '17 at 18:18
  • You just said in your previous comment that you got the numbers already in a jagged array. I am utterly confused... –  Apr 29 '17 at 18:30
  • @elgonzo I just needed help to format the rows all good now. Thanks – Jaruto Apr 29 '17 at 18:35

2 Answers2

1

Let's start from reading one file into array; it's easy with a help of Linq:

using System.IO;
using System.Linq;

...

string path = @"C:\MyFile1.txt";

int[] result = File
  .ReadLines(path)
  .Select(line => int.Parse(line))
  .ToArray(); 

Now, let's have not a single file, but a collection of them:

string[] filePaths = new string[] {
  @"C:\MyFile1.txt",
  @"C:\MyFile2.txt",
  @"C:\MyFile3.txt",
};

int[][] result = filePaths
  .Select(path => File //The inner code looks familiar, right?
    .ReadLines(path)
    .Select(line => int.Parse(line))
    .ToArray()) 
  .ToArray();
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
0

Firstly,You have three text file stored in bid/debug folder.

Section1.txt, Section2.txt, Section3.txt

You can get this text files path.right? So you can store this text file path to string array.

Second:You can get data from each text file by looping this string array.Here how to read data from text file =>http://stackoverflow.com/questions/8037070/whats-the-fastest-way-to-read-a-text-file-line-by-line.

You can get Section 1 string array by splitting string data with "Space" or "\n".

lwin
  • 3,784
  • 6
  • 25
  • 46