Hello all
I have some C# project have 2 classes A and B classes, B inherit from A class
I fill in the A class properties and then I wish to set this vlaues to some object of B type but I failed and I get the following error message "Unable to cast object of type 'Core' to type 'B'"
the code I wrote is as the following :
public class A
{
public A()
{
//
// TODO: Add constructor logic here
//
}
int _ID;
public int ID
{
get
{
return _ID;
}
set { _ID = value; }
}
string _Name;
public string Name
{
get
{
return _Name;
}
set { _Name = value; }
}
}
========================
public class B:A
{
public B()
{
//
// TODO: Add constructor logic here
//
}
int _age;
public int Age
{
get { return _age; }
set { _age=value; }
}
}
B obj = new B();
A objAA = new B();
objAA.ID=12;
objAA.Name = "ssss";
objB =(A) objCore;
objB.Age = 34;
please if any body get what I mean and can help me to cast some object from type A to B please sene me or tell me about somr URL may help me in doing that
Regards
Mostafa