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.
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.
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;
}
}
c is the same for all instances of ClassA in Collection.c belongs to ClassA instead of ClassB, you are right.