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

C#12 Collection expressions are prefixed with two spaces #1009

Closed
Jackenmen opened this issue Nov 13, 2023 · 1 comment · Fixed by #1037
Closed

C#12 Collection expressions are prefixed with two spaces #1009

Jackenmen opened this issue Nov 13, 2023 · 1 comment · Fixed by #1037
Labels
type:enhancement New feature or request
Milestone

Comments

@Jackenmen
Copy link

Jackenmen commented Nov 13, 2023

I wanted to send some feedback about the formatting of the new collection expressions. I think it is inconsistent to prefix these with 2 spaces (I'm also not sure why such formatting was selected) when compared to how e.g. collection/object initializers are formatted:

public class Reproduction
{
    private readonly Dictionary<string, int> counts =  [ ];
    private readonly List<string> keys = { };
}

I'm also not sure I agree with the choice to format collection expressions with spaces between the square brackets and the elements but I suppose it's consistent with how collection/object initializers are formatted so I find it harder to argue against. It is worth noting that MSDN formats these without spaces (while formatting collection/object initializers with spaces between the brackets) and the IDE also suggests such formatting though:
image

@belav belav added this to the 0.27.0 milestone Nov 15, 2023
@belav belav added the type:enhancement New feature or request label Nov 15, 2023
@belav
Copy link
Owner

belav commented Nov 15, 2023

The two spaces was unintentional, and should be an easy fix. Along with changing [ ] to []

I don't recall if I did this intentionally. I'm gonna take another look at it. At first glance I do prefer it without the extra spaces.

Thanks for the feedback!

// input
int[] a = [1, 2, 3, 4, 5, 6, 7, 8];

// output
int[] a =  [ 1, 2, 3, 4, 5, 6, 7, 8 ];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants