I'm currently making a program, that will read data from a file, that contains a number different variables. These being, D - Date , T, R, P and H which are just values. The program will need to add up all the 'T' values, 'R' values , including the P and H values separately. With the same format and outputting the average of each value. ( I'm sure most of it has been done already via the code I currently have). Though, their are some problems that arise. (I'll explain, further down.


The separator char being ':'.

The Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;

//Class Libary IO has been added to the list

class Program

    public static void Main()
        //FileStream file = new FileStream(@"c:\CSharp\CW1_2012.txt", FileMode.Open);
        // StreamReader read = new StreamReader(file);
        // The file will be located and and opened for use further into the program.

        Dictionary<string, List<int>> variableList = new Dictionary<string, List<int>>();
        string whiteSpace = new string(File.ReadAllText(@"c:\CSharp\CW1_2012.txt").Where(dataFile => !char.IsWhiteSpace(dataFile)).ToArray());
        // This strips the file of white space.

        string[] fields = whiteSpace.Split(new char[] { ':' }, StringSplitOptions.None);
        // This splits the  file up into pieces using the semi colon as the point to seperate each char.

        List<int> numbers = new List<int>();
        // This creates a new list.

        foreach (string field in fields
        // This looks through all of the fields.
            if (char.IsDigit(field.FirstOrDefault()))
                List<int> currentlist = null;

                if (!variableList.TryGetValue(field, out currentlist))
                    currentlist = new List<int>();
                    variableList.Add(field, currentlist);


                    foreach (var pair in variableList)
                        Console.WriteLine("{0} {1}", pair.Key, pair.Value.Average());

The problem arises at this section of the program. I get an error saying 'Sequence contains no elements'
I'm unsure what to do from here. I have looked for other solutions and tryed to figure what is wrong but as you can see I havent found one just yet xD

When I try to debugg it , it simply flashes the cmd box for a second so, now im not sure if the program is doing what it is meant to do.


--- Second small problem.

If i can get a fix for the current code, how would I get it to export the data + the produced averages into an excel file? I have this code I would like to use if possible.
            var excelApp = new Excel.Application();

            excelApp.Visible = true;


Excel._Worksheet workSheet =     (Excel.Worksheet)excelApp.ActiveSheet;

            workSheet.Cells[1, "A"] = "ID Number";

            workSheet.Cells[1, "B"] = "Current Balance";

            for (int row = 1; row <= 10; row++)


                workSheet.Cells[row + 1, "A"] = 34*row;

                workSheet.Cells[row + 1, "B"] = "Text here";






using Excel = Microsoft.Office.Interop.Excel;
Thank you for reply in advance