Access sub-class object
Posted
by Amit
on Stack Overflow
See other posts from Stack Overflow
or by Amit
Published on 2010-05-18T07:40:34Z
Indexed on
2010/05/18
7:50 UTC
Read the original article
Hit count: 185
c#
There is a main class containing 2 sub-class(with some prop). If I create an obj of main class, will have access to sub-Class as well b/c we have property defined in main class.
Is thr any way where I pass Main class.SubClass name then it will return that object only ?
can we use indexer ?
MainClass obj = new MainClass();
obj.SubClass1 or obj.SubClass2 ??? Thanks in adv...
class MainClass
{
SubClass1 objSubclass1 = null;
SubClass2 objSubclass2 = null;
public MainClass()
{
objSubclass1 = new SubClass1();
objSubclass2 = new SubClass2();
}
public SubClass1 SubClass1 {get {return objSubclass1;} }
public SubClass2 SubClass2 {get {return objSubclass2;} }
}
Class SubClass1
{
Some properties here...
}
Class SubClass2
{
Some properties here...
}
© Stack Overflow or respective owner