Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# concat/merge of dynamic type variables

in a for loop I receive results from a db as dynamic type

dynamic {system.collections.generic.List<object>}

I need to collect these results into one single variable.

I tried defining a variable

 dynamic results = new List<object>();

and then

 var queryResults = _dbManager.Query(query);
 results = results.Concat(queryResults);

but I have this exception:

 System.Collections.Generic.List<object> does non contain a definition for 'Concat'

I can't find a solution. Do you how can I do this? Thanks!

like image 563
ctt_it Avatar asked Jan 23 '26 09:01

ctt_it


1 Answers

The problem is that dynamic types and extension methods don't work well together (read the explanation of Eric Lippert on the why). You have to call the extension method yourself as a static method (which it actually is):

var l = Enumerable.Concat(results, queryResults);
like image 150
Patrick Hofman Avatar answered Jan 24 '26 21:01

Patrick Hofman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!