❔ Adding list in single line

In C++, I could add a list in a single line using a vector. For example:

std::vector<std::string> months = { "January", "February", "March" };

// another thing I could do:
setMonths({ "January", "February", "March" });


Is there a similar way with C# and lists? That way I'm not calling "Add" 12 times, but keeping them like an array on initialization.

With C#, I think it's just
List<string> months = new List<string>();
months.Add("January");
months.Add("February");
months.Add("March");


Or AddRange(): -- Which isn't too bad, but still feels bigger than it should be.
        List<string> vMonths = new List<string>();
        string[] months = new string[] { "January", "February", "March" };
        vMonths.AddRange(months);
        dt.SetMonths(vMonths);  


Ideal:
dt.SetMonths({ "January", "February", "March" });  // Param: SetMonths(List<string> list)
Was this page helpful?