I want a variable to only contain types of classes that inherit a specific abstract. In this example, the variable "MyLetter" is supposed to only contain the types LetterA, LetterB, or anything that inherits LetterAbstract.
How would I accomplish this?
abstract class LetterAbstract
{
public char Letter;
}
class LetterA : LetterAbstract
{
void LetterA()
{
Letter = 'A';
}
}
// valid
TLetterAbstract MyLetter = typeof(LetterA);
// invalid
TLetterAbstract MyLetter = typeof(string);