How to change scenes in c#?

Godot Version

4.2.2 Godot.NET

Question

I am working on a basic main menu and I wanted to try and turn my GDScript into C#.
The code for C# is as follows:
This code doesn’t work

using Godot;

public partial class NewMainMenu : Node
{
    private void _on_level_1_play_pressed()
    {
        GetTree().ChangeScene("res://scene/level1.tscn");
    }

    private void _on_level_2_play_pressed()
    {
        GetTree().ChangeScene("res://scene/level2.tscn");
    }

    private void _on_level_3_play_pressed()
    {
        GetTree().ChangeScene("res://scene/level3.tscn");
    }
}

The errors I am getting are as follows

CS1061: ‘SceneTree’ does not contain a definition for ‘ChangeScene’ and no accessible extension method ‘ChangeScene’ accepting a first argument of type ‘SceneTree’ could be found (are you missing a using directive or an assembly reference?) /Users/username/Godot_Projects/scene/newMainMenu.cs(7,13)
CS1061: ‘SceneTree’ does not contain a definition for ‘ChangeScene’ and no accessible extension method ‘ChangeScene’ accepting a first argument of type ‘SceneTree’ could be found (are you missing a using directive or an assembly reference?) /Users/username/Godot_Projects/scene/newMainMenu.cs(12,13)

The GDScript I am using that worked was:

extends Node

func _on_button_pressed():
	get_tree().change_scene_to_file("res://scene/level1.tscn")


func _on_button_2_pressed():
	get_tree().change_scene_to_file("res://scene/level2.tscn")

Is there something I have done wrong? How do I get the C# code to work

Hello,
you have to load scene first and then add as root child:

var scene = ResourceLoader.Load<PackedScene>("res://scene/level1.tscn").Instantiate();
GetTree().Root.AddChild(scene);

and remove existing scene from root.

more info

One of my scripts

public partial class ButtonAcceptStartGame : Button
{
    public override void _EnterTree() => Pressed += OnButtonPressed;
    public override void _ExitTree() => Pressed -= OnButtonPressed;
    private void OnButtonPressed() => GetTree().ChangeSceneToFile("res://Scenes/intro.tscn");
}

if you have many scenes you can make export path variable