RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Create an object from parent to derived class !

Ikkerh

Sorceror
How can i create parent's class object to derived class without loss data ?

Example:
Code:
class BaseClass
{
}

class A_Class : BaseClass
{
    public int i;
}

class B_Class : A_Class
{
}

class MainClass
{
    public static void ExampleMethod()
    {
        A_Class a = new A_Class();
        a.i = 5;

        B_Class b = a as B_Class; // it's wrong

        /* I want to convert the A_Class to the B_Class without loss the variable "i" */
    }

}

P.S. Do you understand me ?
 

Jeff

Lord
You cannot do that. If the object was created as class A, it cannot be class B. Can you explain what you are really trying to do... chances are, you are going about it incorrectly.
 
Top