How to instantiate a scene on C#

Godot Version

4.2 Mono (C#)

Question

[ExportGroup("Bow Settings")]
[Export]
private AnimatedSprite2D BowSprite;
        
[Export]
private PackedScene Arrow;
private void Shoot()
{
    Node NewArrow = Arrow.Instantiate();
    NewArrow.Position = GlobalPosition; // NewArrow dont have a Position
    ParentIsWorld.AddChild(NewArrow);
}

I tried this method, however it doesn’t work I think due to the fact that initially when instantiating the scene, the arrow is of type Node (even if I name it dynamically var, nothing changes). Saw similar code on GDScript and it worked.

Try the below, you need to cast to Arrow since Node.Instantiate() returns a more abstract type of Arrow.

private void Shoot()
{
    Arrow newArrow = Arrow.Instantiate() as Arrow;
    newArrow .Position = GlobalPosition;
    ParentIsWorld.AddChild(newArrow);
}