-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[.NET] Use collection expressions in docs #100685
[.NET] Use collection expressions in docs #100685
Conversation
As of C# 12 we can now use collection expressions to reduce some boilerplate when initializing collections.
GD.Print(array[0]); // Prints "First" | ||
GD.Print(array[2]); // Prints 3 | ||
GD.Print(array[array.Count - 1]); // Prints "Last" | ||
GD.Print(array[^1]); // Prints "Last" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this common knowledge? As a not particularly savvy C# developer, I don't find this shorthand to be more understandable at a glance. Of course, code style is up to you though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say so, it's at the very least equivalent to GDScript's negative indexes, which I don't find any easier to understand.
But I imagine the reason why the GDScript example uses negative indexes is to teach users that they can use them to access elements from the end of the array. In a similar way, we can use the C# example to teach them how to do the same thing in C#. So it probably doesn't matter if they're not familiar with this syntax.
Not being familiar with C# versioning but what is the minimum version we support? Is C# 12 expected to be what everyone uses, just so that any code in the docs will work for everyone |
Yes, .NET 8 defaults to C# 12, which is the new minimum required since Godot 4.4. |
Thanks! |
As of C# 12 we can now use collection expressions to reduce some boilerplate when initializing collections.