using System.Collections.Generic;
public class Character { public string Name { get; init;} }
public class Hero : Character {}
public class Creature : Character {}
public interface IActorController<out T> where T : Character {
public void ShowActorName();
public abstract class ActorController<T> : IActorController<T> where T : Character
public T Actor { get; init; }
public virtual void ShowActorName() {
Console.WriteLine(Actor.Name);
public class HeroController : ActorController<Hero> {
public override void ShowActorName() {
Console.WriteLine("The hero name is " + Actor.Name);
public class CreatureController : ActorController<Creature> {}
public static List<IActorController<Character>> ActorControllers = new();
public static void Main()
var heroController = new HeroController() { Actor = new Hero() { Name = "Mr. Foo Hero" } };
var creatureController = new CreatureController() { Actor = new Creature() { Name = "Mr. Bar Creature" } };
Zone.ActorControllers.Add(heroController);
Zone.ActorControllers.Add(creatureController);
foreach(var actorController in Zone.ActorControllers) {
actorController.ShowActorName();