I want to do an explicit cast using Type information from one array to another which is related by inheritance. My problem is that while casting using Type information the compiler throws error, but my requirement is to dynamically cast based on the Type information provided.
Please Help
class Program
{
static void Main(string[] args)
{
Parent[] objParent;
Child[] objChild = new Child[] { new Child(), new Child() };
Type TypParent = typeof(Parent);
//Works when i mention the class name
objParent = (Parent[])objChild;
//Doesn't work if I mention Type info
objParent = (TypParent[])objChild;
}
}
class Parent
{
}
class Child : Parent
{
}