Reputation: 123
I am being given a list of dynamic objects (the results of a SQL query). I can access any value of a specific element if I know the name of the column to access. However there are an unknown number of columns with unknown names.
How can I generate a list of the column names from the dynamic objects? I'm trying to avoid querying the DB again for information I should already have in this list. If I can get a list of strings with the column names of this table I should be able to access the data as I like.
Thanks in advance for any suggestions.
Upvotes: 0
Views: 847
Reputation: 1063629
dynamic
can mean different things. What you need to look at is what the objects actually are. Likely options:
IDictionary<string,object>
etc) - in which case cast as the dictionary and access the keysUpvotes: 3