C#C
C#2y ago
jborean

Init only collection property contructor from IEnumerable

I was wondering if there was a way to assign an IEnumerable to a init only collection property. For example I can do
ProcessStartInfo psi = new()
{
    ArgumentList = { "foo", "bar" },
};

But I was wondering if I could somehow do
IEnumerable<string> arguments = ...;
ProcessStartInfo psi = new()
{
    ArgumentList = arguments,
};

I'm currently just looping through the enumerable and doing psi.ArgumentList.Add(a); as a fallback but just wanted to check if there was another way
Was this page helpful?