Witam.
Mam klase Igredient :
internal class Igredient
{
private string youWannacalc;
private string Name { get; set; }
public List<Igredient> ListIgredient { get; set; }
public List<Igredient> AddIdredient()
{
var listIgredients = new List<Igredient>();
do
{
Console.WriteLine("Add Name of Idgredient");
string nameOfIdgredient = Console.ReadLine();
listIgredients.Add(new Igredient() { Name = nameOfIdgredient });
youWannacalc = StringOperation.ReadParameter("If you wanna add next idgredient enter YES");
}
while (youWannacalc == "YES");
/ //Console.WriteLine("----------------------------------");
//Console.WriteLine("It is a list available ingredients");
//foreach (var item in listIgredients)
//{
// Console.WriteLine($"{item.Name} ");
//}
return listIgredients;
}
}
I chcialbym w metodzie main uzyc metody AddAddIdredient ktora stworzy mi nowa liste i ta liste przypisze do mojego proporty czyli listy w klasie Igredient
W klasie main tworze taki zapis :
var idredients = new Igredient();
idredients.AddIdredient();
Jednak to nie przypisuje mi wartosci do listy ktora utworzylem w klasie Idgredience.
Chcialbym pozniej odczytac liste skladnikow za pomoca metody ktora stworzylem(jak na razie pokazuje nulle) :
ShowList(idredients.ListIgredient);
public static void ShowList ( IEnumerable<object> giveList)
{
foreach (var item in giveList)
{
Console.WriteLine(item);
}
}
Prosze rowniez o wytlumaczenie jak to wszystko robic, dlaczego robie to zle i ewentualnie pozniej odeslac do literatury to sobie doczytam.