I feel like this has a really simple answer and I just can't get to it, but here's my shot on it after not finding anything related on the internet.
Esentially, I would like to do something like this from javascript in C#:
var abc = ["a", "b", "c"]
var abcd = [...abc, "d"]
"Spreading" the content of the one-dimensional array abc
into another one-dimensional array abcd
, adding new values during initialization.
Replicating this behaviour in C#, however, won't work as intended:
string[] abc = { "a", "b", "c" };
string[] abcd = { abc, "d" };
The closest I got to replicating this in C# was with Lists, like so:
string[] abc = { "a", "b", "c" };
var abcd = new List<string>();
abcd.AddRange(abc);
abcd.Add("d");
I could've saved a line in the above example by directly initializing the List with the "d" string (the order doesn't matter to me, I'll just be checking if the collection contains a certain item I'm looking for), but using a List is in itself highly inefficient in comparison to initializing an array since I have no intention on modifying or adding items later on.
Is there any way I can initialize a one-dimensional array from other one-dimensional arrays in one line?