
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 0.57 KB | hits: 10 | expires: Never
How is it possible to create an object from the abstract class?
System.Array myIntArray = Array.CreateInstance(typeof(int),10);
Array a = Array.CreateInstance(typeof(int), 10); //create some array
Type type = a.GetType(); // type is int[], which is not abstract
Type baseType = type.BaseType; // baseType is Array
abstract class Animal
{
public static Animal CreateInstance(AnimalType animalType)
{
if (animalType == AnimalType.Cat)
return new Cat();
if (animalType == AnimalType.Dog)
return new Dog();
// etc.
}
}