Re:Introducing C# in Godot
by Arnavion on Saturday October 21, 2017 @10:26PM
(#15524816)
Note to the author: Since you specifically point out that C# 7.0 is supported, this example:
would be better written as:
[ Parent
| on HN ]
Re:Introducing C# in Godot
by tonyedgecombe on Sunday October 22, 2017 @06:56AM
(#15526152)
Or:
if (ev is InputEventMouse mouseEvent)
{
Vector2 mousePos = mouseEvent.Position;
}
else if (ev is InputEventKey keyEvent)
{
bool aPressed = keyEvent.Pressed && keyEvent.Scancode == GD.KEY_A;
}I think switch blocks are only worth it when you have 2 or more `else if`, otherwise a normal `if` is more readable IMHO.
Normally I'd agree, but I really like the concise but readable way this handles the casting for you.