i have a base class and derived class like below
public class BaseClass
{
public int No { set; get; }
}
public class Derived : BaseClass
{
public string Name { set; get; }
}
when i create instance of base class and want to downcast it to derived class it returns InvalidCastOperation.
class Program
{
static void Main( string[] args )
{
BaseClass bas = new BaseClass();
Derived derived = (Derived)bas; // invalid cast operation. why?
System.Console.WriteLine();
}
}
I am wondering why it does not work? and is a solution to implement this request?