Answer: Yes, we can create an instance of class aa from
the instance of class cc
add this code snippet
(after the end of the definition of class cc)
class result
{
static void Main(string[] args)
{
cc obj = new cc();
//get the base type of cc
Type b = obj.GetType().BaseType;
//It will be bb
Console.WriteLine(b.Name);
// again get parent for bb type, which is aatype
Type a = b.BaseType;
// create a instance usng Activator.CreateInstance
object o = Activator.CreateInstance(a);
Console.WriteLine(o.GetType().Name);
//It will be aa
}
}
Asked In: Many Interviews |
Alert Moderator