Skip to content

Implicit index indexer doesn't work in object initializer #67533

@AlekseyTs

Description

@AlekseyTs
class C
{
    public Buffer10 F = new Buffer10();
}

class Program
{
    static void Main()
    {
        M2().F[^1] = 123;
    }

    static C M2() => new C() { F = {[^1] = 111} }; // error CS1913: Member '[^1]' cannot be initialized. It is not a field or property.
}

struct Buffer10
{
    private int[] _array = new int[10];

    public Buffer10()
    {}

    public int Length => 10;
    public int this[int x] 
    {
        get => _array[x];
        set { _array[x] = value; }
    }
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions