I am initialising and array from items in a list as follows:
MyArray[] Arrayitems = SomeOtherList
.Select(x => new MyArray[]
{
ArrayPar1 = x.ListPar1,
}).ToArray()
I have a secondary List that i would like to add to the same array inline in the initialiser, something like this ():
MyArray[] Arrayitems = SomeOtherList
.Select(x => new MyArray[]
{
ArrayPar1 = x.ListPar1,
}).ToArray()
.Join(
MyArray[] Arrayitems = SomeOtherListNo2
.Select(x => new MyArray[]
{
ArrayPar1 = x.ListPar1,
}).ToArray()
);
Is this possible or will i have to combine everything before the initial select statement?
You can use Concat
:
MyArray[] Arrayitems = SomeOtherList.Concat(SomeOtherListNo2)
.Select(x => new MyArray()
{
ArrayPar1 = x.ListPar1,
}).ToArray();
If items could be contained in both lists and you want them only once in your result, you can use Union
:
MyArray[] Arrayitems = SomeOtherList.Union(SomeOtherListNo2)
.Select(x => new MyArray()
{
ArrayPar1 = x.ListPar1,
}).ToArray();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With