Home > front end >  C# linq how to build expandoobjects into a list?
C# linq how to build expandoobjects into a list?

Time:02-11

I am trying to select expandoobjects (qs_ll[0][0]) from List<dynamic> and build them into a new list.

I have managed to use GetRange() and .concat() to select and combine sublists. It does work, but it is rather verbose. I would fancy the index method as it looks tidy.

I currently trying like Enumerable.Concat(qs_ll[0][0],qs_ll[0][1]). However, the result turn out to be a series of objects [column name,value] and it does not have ToList(). I would like it keep the structure of expandoobjects{value1,value2,value3,...}.

I assume it can be done with the use of certain functions.

CodePudding user response:

Alright, I find the most straightforward way by myself (it is just there all the time).

new List<dynamic>{qs_ll[0][0], qs_ll[0][1]};

I have been thinking of it in a merging lists manner, forgetting the fact that those variables are just elements which would just build a list. To build elements into a list, how could it be done easier by just new List<>{ele1,ele2,...};?..

  • Related