First of all, I want to say that I'm new to C#, so this question may seem completely off track.
I have a set of enumerables called ShapeType:
Cube, Sphere, Rectangle, Ellipse
And a method to return a random value from the enumerables:
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;
}
Every enumerable has a corresponding concrete class. And the question I'm wondering about is if you can instantiate a class by using the random enumerable value randomShape, kind of like this:
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(); // *Here use the randomShape-variable as type*
return shape;
}
Is this possible or is it just wishful thinking?
int
conversion (where enum value is used now).