C#: I have this dictionary: Dictionary<string, Object> ourAnimals = new ();
Each key is a string, such as "d1".
Each value is an object. Here is the class definition for those objects: class Pet {
public string species;
public string age;
public string physicalDescription;
public string personalityDescription;
public string nickname;
public string suggestedDonation;
public Pet(string Species, string Age, string PhysicalDescription, string PersonalityDescription, string Nickname, string SuggestedDonation) {
species = Species;
age = Age;
physicalDescription = PhysicalDescription;
personalityDescription = PersonalityDescription;
nickname = Nickname;
suggestedDonation = SuggestedDonation;
}
void printPet() {
Console.WriteLine(nickname);
Console.WriteLine(species);
Console.WriteLine(age);
Console.WriteLine(physicalDescription);
Console.WriteLine(personalityDescription);
Console.WriteLine(suggestedDonation);
}
}
What I'd like to do is print the key/value pairs (formatted, of course) of each item in the dictionary.
I even included a method to print the values of the object, should I not find a way to do the above. I can't even figure out how to call that for each dictionary entry.
How do I access the values and/or method of those objects in the dictionary? I had the same problem in PowerShell.
Incidentally, trying to do a web search on this question only results in about a million pages on how to create objects or dictionaries, but not how to handle dictionaries of objects, or dictionaries of dictionaries for that matter.
BTW, you may recognize this example as part of the c# tutorials on learn.microsoft.