Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Choose a random subclass of a class

$
0
0

Suppose I have a class Letter and a lot of classes A, B, ..., all of them inherit from Letter.

How can I choose a random child of Letter?

I know it sounds a bit broad, but what I want is something like this

public Letter GetRandomLetter(){    //return a random instance of A, B or any child class}

The number of child classes is unknown so I can't just use some logic with random numbers to return an instance of each child class. I also don't want to use reflection.


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>