How can i??
-
How can i build a program that hv two classes (child class and parant class) child class is inheriting from parant class. Now child class has two methods 1.which returns the name of parant class 2.which returns the object of parant class
-
How can i build a program that hv two classes (child class and parant class) child class is inheriting from parant class. Now child class has two methods 1.which returns the name of parant class 2.which returns the object of parant class
Hi you could use reflection. This would be in the child class.
public string GetParentClassName() { return this.GetType().BaseType.Name; }
Hmm, the child itself is an object of the parent class. Don't know exactly what you mean with this. Regards SebastianIt's not a bug, it's a feature! Me in Softwareland.
-
How can i build a program that hv two classes (child class and parant class) child class is inheriting from parant class. Now child class has two methods 1.which returns the name of parant class 2.which returns the object of parant class
I am not sure what do you mean by saying the Name and Object of parent class, but you can get the Type of the base class like this: public class Dad { } public class Kid : Dad { public Type GetParentType() { return this.GetType().BaseType; } }
Regards, Lev
-
I am not sure what do you mean by saying the Name and Object of parent class, but you can get the Type of the base class like this: public class Dad { } public class Kid : Dad { public Type GetParentType() { return this.GetType().BaseType; } }
Regards, Lev
thanks... thats what i want... this was my 1st post on this site... i really like this platform...
-
How can i build a program that hv two classes (child class and parant class) child class is inheriting from parant class. Now child class has two methods 1.which returns the name of parant class 2.which returns the object of parant class
Hi when you create a class that inherit from another class you must specify the base class type, this is the solution for your question.
class Base { public Base() { } } class Derieved : Base { public string GetPerentName() { return typeof(Base).Name; } public Base GetPerentObject() { return (Base)this; } }