Skip to content
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

Merged
merged 1 commit into from
Dec 23, 2024

Conversation

raulsntos
Copy link
Member

@raulsntos raulsntos commented Dec 21, 2024

As of C# 12 we can now use collection expressions to reduce some boilerplate when initializing collections.

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"
Copy link
Contributor

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.

Copy link
Member Author

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.

@AThousandShips
Copy link
Member

As of C# 12

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

@raulsntos
Copy link
Member Author

raulsntos commented Dec 21, 2024

Yes, .NET 8 defaults to C# 12, which is the new minimum required since Godot 4.4.

@Repiteo Repiteo merged commit 7b42fb9 into godotengine:master Dec 23, 2024
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Dec 23, 2024

Thanks!

@raulsntos raulsntos deleted the dotnet/collection-expressions branch December 24, 2024 05:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants