Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.57 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How is it possible to create an object from the abstract class?
  2. System.Array myIntArray = Array.CreateInstance(typeof(int),10);
  3.        
  4. Array a = Array.CreateInstance(typeof(int), 10); //create some array
  5. Type type = a.GetType(); // type is int[], which is not abstract
  6. Type baseType = type.BaseType; // baseType is Array
  7.        
  8. abstract class Animal
  9. {
  10.     public static Animal CreateInstance(AnimalType animalType)
  11.     {
  12.         if (animalType == AnimalType.Cat)
  13.             return new Cat();
  14.         if (animalType == AnimalType.Dog)
  15.             return new Dog();
  16.         // etc.
  17.     }
  18. }