I’m trying to calculate how many of each type of object is in the dictionary to display them, however, when calculating amateur-type objects, it also takes into account all objects like “Professional” and “Celebrity”, because they are amateur children. Is there a way to fix this WITHOUT deleting inheritance and just counting objects only of type Amateur?
Code example:
private void GetTotalEntries() { string amateurEntries; string profEntries; string celebEntries; amateurEntries = manager.competitors.Values.OfType<Amateur>().Count().ToString(); profEntries = manager.competitors.Values.OfType<Professional>().Count().ToString(); celebEntries = manager.competitors.Values.OfType<Celebrity>().Count().ToString(); EntriesTextBox.Text = "Amateur Entries:" + amateurEntries + "\nProfessional Entries:" + profEntries + "\nCelebrity Entries:" + celebEntries; }
source share