I have the problem, that I don't know how to get the properties of an object that is listed in a dictionary.
E.g.
public class Person
{
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
}
In another class I created some objects from "Person" with the names Peter, Paul and Marie and saved them in a dictionary like this:
Dictionary<string,> persons = new Dictionary<string,>();
persons.Add("Person1", new Person{ Name = Peter });
persons.Add("Person2", new Person{ Name = Paul });
persons.Add("Person3", new Person{ Name = marie });
Now I want to get the value of the property "Name" from the object which is paired with the key "Person1".
How to solve this problem??
EDIT:
It just made "click" in my head and I found the solution which will work for my situation:
Person personName;
persons.TryGetVale("Person1", out personName);
string wantedName = personName.Name;
Sorry that I opened this question... I did not think that I get the solution just a few minutes later than I asked this question...