2. I've a class Parent Class A and a Derived Class B. Here
is a scenario.
I've an instance of Class A as objA and an instance of Class
B as objB.

I can refer a child class variable as objB=objA, but
cannot do objA=objB what is the reason?



Answer Posted / ashok

Is this you are trying to do?

class A
{
public int MyName { get; set; }
}

class B : A
{
public int MyName1 { get; set; }
}

public class TestAB
{
public static void Test()
{
A objA = new A();
B objB = new B();



objB = (B)objA; // Unable to cast object of type
'AdvanceLib.A' to type 'AdvanceLib.B'.
objA = objB;

}

}

---

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the number or character entered through keyboard gets converted to equivalent ascii code & it get stored on ram in the binary form.

523


which is the institute in hyderabad for providing the live project industry training

2337


Can I create my own metadata attributes?

535


any one can explain about projectarchitecture and project approach briefly

2069


What are relation objects in dataset?

551






Explain the number or character entered through keyboard gets converted to equivalent ascii code & it get stored on ram in the binary form. What is the exact procedure. : Dot net architecture

534


Why the config file might not be writable

573


Does application frame need host?

498


i wish to write mcts(microsoft certified technology specialist) exam. can anyone give the model question or format and preparation method?

2313


What is password attribute of the textbox control of .net mobile? : Microsoft dot net mobile

469


Explain the Lapsed Listener problem in .net

674


Explain the types of memory management? : .NET Architecture

525


Can you Explain element .net mobile with example? : Microsoft dot net mobile

488


Explain about httpruntime.cach.get(); method?

575


What's new in the .net 2.0 class library?

544