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

The implicit index access example seemed not working #42674

Closed
WeihanLi opened this issue Sep 21, 2024 · 1 comment
Closed

The implicit index access example seemed not working #42674

WeihanLi opened this issue Sep 21, 2024 · 1 comment
Labels
dotnet-csharp/svc Pri1 High priority, do before Pri2 and Pri3 resolved-by-customer Indicates issues where the customer no longer needs any help. [org][resolution] whats-new/subsvc

Comments

@WeihanLi
Copy link
Contributor

WeihanLi commented Sep 21, 2024

Type of issue

Code doesn't work

Description

The implicit index access example seemed not working

image

int[] numbers =
{
   [^1] = 4,
   [^2] = 3,
   [^3] = 2,
   [^4] = 1,
};

CS0131: The left-hand side of an assignment must be a variable, property or indexer

And I'm using the latest vs preview and targeted net9.0 with .NET 9 RC1 SDK installed

Page URL

https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-13#implicit-index-access

Content source URL

https://github.com/dotnet/docs/blob/main/docs/csharp/whats-new/csharp-13.md

Document Version Independent Id

587ed47f-f532-e018-9b0d-6ee76afd20e4

Article author

@BillWagner

Metadata

  • ID: c36588d0-6bdf-1740-220c-10b20bb88730
  • Service: dotnet-csharp
  • Sub-service: whats-new
@dotnet-bot dotnet-bot added the ⌚ Not Triaged Not triaged label Sep 21, 2024
@issues-automation issues-automation bot added dotnet-csharp/svc Pri1 High priority, do before Pri2 and Pri3 whats-new/subsvc labels Sep 21, 2024
@WeihanLi
Copy link
Contributor Author

The array needs to be inside of an object, there's an example

internal class ImplicitIndexAccessSample
{
    public static void Main()
    {
        var a = new TestClass()
        {
            Numbers =
            {
                [0] = 3,
                [^1] = 1
            }
        };
        foreach (var item in a.Numbers)
        {
            Console.WriteLine(item);
        }

        // output 3 0 1
    }
}

file sealed class TestClass
{
    public int[] Numbers { get; init; } = new int[3];
}

@dotnet-bot dotnet-bot added resolved-by-customer Indicates issues where the customer no longer needs any help. [org][resolution] and removed ⌚ Not Triaged Not triaged labels Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotnet-csharp/svc Pri1 High priority, do before Pri2 and Pri3 resolved-by-customer Indicates issues where the customer no longer needs any help. [org][resolution] whats-new/subsvc
Projects
None yet
Development

No branches or pull requests

2 participants