C# .NET - Regarding inherited class issue
Asked By shoaib mansoori
04-Feb-12 01:50 AM
Hello,
there is two class
one is ClassA
other is ClassB
ClassB is inheriting the ClassA that means ClassA is a base class.
like..
Class ClassA
{
void method1()
{
console.writeLine("Base class is called")
}
}
Class ClassB:ClassA
{
void method2()
{
console.writeLine("Child class is called")
}
}
but calling is this way:
ClassA A=new ClassB();
ClassB b=new ClassA();
what this line means ClassA A=new ClassB();
thanks
regards
Amit Choudhary replied to shoaib mansoori
ClassA A=new ClassB();
It means that classA object can contain ClassB object Since ClassA is Base Class.
Any Base class can have object of derived class.
USES:
If A Base class 3 different type of derived classes then One object of base class can have all 3 type of object assigned.
Help with Linq To Object .NET Framework Hi group, here's my code : public class ClassA { public List<ClassB> ClassB { get; set; } } public class ClassB { public int value; } static void Main() { List<ClassA> list = new List<ClassA> { new ClassA { ClassB = new List<ClassB> { new ClassB { value = 1 }, new ClassB { value = 2 }, } }, new ClassA { ClassB = new List<ClassB> { new ClassB { value
Accessing property inside a property I curently have a set up like below public class ProptsClass { public class ClassA { public list< ClassB > pcb {get; set;} } pubic class ClassB { public list< ClassC > pcc {get; set;} } public class ClassC { public string _someproperty {get; set;} } } what I want to do is to databind object as < %#Eval("Namespace.ProptsClass.ClassA.pcb.pcc._someproperty")% > I get a "DataBinding: Namespace.ProptsClass.ClassA + ClassB' does not contain a property with the name '_someproperty'.error Can somebody tell me where net. Thanks in advance Hi Madhu, Please take a close look to your code. In class ClassA you have defined the return type of pcb property as list<ClassB> , and same
Doubt in Inheritance public abstract class AbstractA { public abstract void Save(DataTable ctlDTable); } public class ClassB :AbstractA { public override void Save(DataTable ctl) { } } public class ClassC:AbstractA { public override void Save(DataTable ctl) { } } private void Button1_Click(object sender, System.EventArgs Obj = new Test123(); / / Binterface objB = (Binterface ) Obj / / objB.Add(1, 2, 3).ToString(); DataTable dt; ClassB ClsBObj = new ClassB(); AbstractA a1 = (AbstractA)ClsBObj; a1.Save(dt); } I want to know a1 class name. Whether I have to use Reflection … any other option a1 here belongs to ClassB object . . How to chk tha t. . if(a1 is ClassB) Response.Write("ClassB"); else if
calling child class method Can any one give me the e xample of calling child class method from Base class? A child class? Does the base class inherit your child class or does your child class inherit from base? Elaborate. . . Hello waqar, You can Call the parent class or Base class from Child class or derived class. See the below example: using System