Search code examples
c#immutable-collections

ImmutableList does not contain a constructor that takes 0 arguments


I'm trying to initialize an immutable list like a regular list, but it's telling me it doesn't take 0 arguments. It throws the same error if I pass 1 argument, 2 arguments, etc.

public static readonly ImmutableList<object[]> AddressTestCases = new ImmutableList<object[]>
{
    new object[]{ "", false },
    new object[]{ "testestest", true },
};

What am I doing wrong here? Is there a way to do this without using .Add?


Solution

  • Ok ImmutableList has a create method that you should be using

    public ImmutableList<int> ImmutableListCreate()
    {
        return ImmutableList.Create<int>(1, 2, 3, 4, 5);
    }