Moving to other game states with ScreenManager I'm creating a game in C#, and I've created a ScreenManager so I can call

ScreenManager.MoveToScreen(typeof(ScreenClassHere))


to move to other game states. However, I feel that my method of creating an instance of the class is... not very optimal. See for yourself.

    public static void MoveToScreen(Type s)
    {
        if (currentscreen != null) currentscreen.Remove();

        currentscreen = (Screen)s.GetConstructor(System.Type.EmptyTypes).Invoke(null);
        currentscreen.Init();
    }


Does anyone know if there's a better way to create an instance of a certain class from a Type?
You could use generics

public static void MoveToScreen&lt;T&gt;() where T : Screen, new()
{
    if (currentscreen != null) currentscreen.Remove();

    currentscreen = new T();
    currentscreen.Init();
}


In this case, you'd have to call the method as

ScreenManager.MoveToScreen&lt;ScreenClassHere&gt;();