First of all, I want to say that I am new to C #, so this question may seem completely inoperative.
I have a set of enumerations called ShapeType:
Cube, Sphere, Rectangle, Ellipse
And a method to return a random value from enumerations:
private static ShapeType GetRandomShape()
{
Array values = Enum.GetValues(typeof(ShapeType));
Random random = new Random();
ShapeType randomShape = (ShapeType)values.GetValue(random.Next(values.Length));
return randomShape;
}
Each enumerated has a corresponding concrete class. And the question I'm interested in is creating an instance of the class using the random enumerated value randomShape, sort of like:
private static Shape GetRandomShape()
{
Array values = Enum.GetValues(typeof(ShapeType));
Random random = new Random();
ShapeType randomShape = (ShapeType)values.GetValue(random.Next(values.Length));
Shape shape = new randomShape();
return shape;
}
Is this possible or is it just wishful thinking?
source
share