How to save data from an array [closed]

Split problem into lesser ones:

  • How would you like to save an item to string in a file
  • How would you like to read (parse) an item from a string (line) of the file?

in case school grades are just ints:

int[] grades = new int[] {2, 3, 4, 5, 2};

the answers for the questions above can be item.ToString() and int.Parse(line) and so you can put

  .WriteAllLines(@"C:\MyData.txt", grades
  .Select(grade => grade.ToString()));


int[] grades = File
  .Select(line => int.Parse(line))

Browse More Popular Posts

Leave a Comment