static public Sauce[] ChooseIngredientsFromList(Sauce[] ingredients) { for (int i = 0; i < ingredients.Length; i++) { Console.WriteLine("\t {0} {1}", i, ingredients[i].Name); } Console.WriteLine("Choose ingredients from the list please use numbers(for example: 1,2,3,4,5,6): "); string[] buffer = Console.ReadLine().Split(','); Sauce[] chosenIngredients = new Sauce[buffer.Length]; for (int i = 0; i < buffer.Length; i++) { chosenIngredients[i] = new Sauce(); chosenIngredients[i] = ingredients[Int32.Parse(buffer[i])]; } return(chosenIngredients); }
static public Sauce[] GetSauce(string path) { int i = 0; using (StreamReader sr = File.OpenText(path)) { while (!sr.EndOfStream) { string[] buffer = new string[5]; buffer = sr.ReadLine().Split('/'); if (buffer[4] == "sauce") { i++; } } } Sauce[] sauce = new Sauce[i]; i = 0; using (StreamReader sr = File.OpenText(path)) { while (!sr.EndOfStream) { string[] buffer = new string[5]; buffer = sr.ReadLine().Split('/'); if (buffer[4] == "sauce") { sauce[i] = new Sauce(); sauce[i].Name = buffer[0]; sauce[i].Callory = Int32.Parse(buffer[1]); sauce[i].Price = Int32.Parse(buffer[2]); sauce[i].StorageTime = Int32.Parse(buffer[3]); i++; } } } return(sauce); }