Reputation: 583
Situation:
ClassA
{
static string c;
}
ClassB
{
public List<ClassA> Collection;
}
....
ClassB b;
How can I get access to a static
member of ClassA
having object b
of ClassB
? Here it is string c
.
Upvotes: 0
Views: 735
Reputation: 156948
You can't get static members from a class instance (so you can't do b.Collection[0].c
).
You do have the ability to use reflection to get the type member, but that wouldn't be the best option in my opinion.
I think you'd better create a non-static accessor for the static member:
public string C
{
get
{
return c;
}
}
Upvotes: 1