static void LoadExpenses(string filename)
 {
     string[] lines = System.IO.File.ReadAllLines(filename);
     expenses = new Expense[lines.Length];
     for (int i = 0; i < lines.Length; i++)
     {
         expenses[i] = new Expense(lines[i]);
     }
 }
Exemple #2
0
        static Expense[] expenses; //an instance of the class Expense called expenses

        #endregion Fields

        #region Methods

        //function taking one string as a parameter to use as a the name of a file to access
        static void LoadExpenses(string filename)
        {
            string[] lines = System.IO.File.ReadAllLines(filename);//creates a string array called lines and populates it with lines from the file with the name that was passed to the function
            expenses = new Expense[lines.Length];//expenses is given the same number of elements as lines
            for (int i = 0; i < lines.Length; i++)
            {
                expenses[i] = new Expense(lines[i]);//passes the current string in lines to the constructor of Expense to be converted in to an element in expenses
            }
        }