Opinion Poll не печата на конзолата
Здравейте, като използвам linq върху list не печата нищо на конзолата. Ако махна linq-a и печата и нз какво става ?
Като филтрирам листа с Linq в нов лист и дебъгна виждам че нищо не се пълни в новия лист
https://pastebin.com/wRudRYJ6 Main method
https://pastebin.com/P7jiKC7n Person класът ми е добавен с референция от друг project
Main:
Statistics:
Person:
@Axiomatik,
thank you again! In fundamental module you help me so much to take in the classes.
Your class name "Statistics" is better than my class name "People" and in your method "AddStatistics" you don't add the person if list already content person. And I will add this validation in my AddPerson method.
I write properties without return and whitout declare private fields is this bad practice?
Best,
Eli
Setting up properties and private fields will be explained in detail in C#-Advanced and OOP. Usually properties are configured with {get; set;}, while private fields should be validated through public properties. Practise with the exercises and exams and things will start to get clearer in the process.
Best,
@Axiomatik
By the way I'am confident whitout testing in Judge your solution is 100/100, but when I use this condition in my Add method which is very similar to your Add method:
public void AddPerson(Person person)
{
if (!ListWithPersons.Contains(person))
{
this.ListWithPersons.Add(person);
}
}
With input:
3
Stamat 31
Stamat 31
Stamat 31
I have otput:
Stamat - 31
Stamat - 31
Stamat - 31
In Fundamental module you show me "Any" (I think the exercise was "Game store" :) ):
public void AddPerson(Person person)
{
if (!ListWithPersons.Any(p=> p.Name == person.Name))
{
this.ListWithPersons.Add(person);
}
}
With input:
3
Stamat 31
Stamat 31
Stamat 31
Otput is correct:
Stamat 31
Maybe I'am might be wrong, byt please check your Add method and thanks again about your solution, it helps me very much and for next exercise.
Have a nice weekend!