Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use Select in dynamic list?

I have dynamic models in my dynamic list. attributes.blabla exist on
all my models.

        dynamic reqList= new List<dynamic>();
        
        //filled this list

        List<string> blablaList = reqList.Select(x => x.attributes.blabla).ToList();

I am taking this error

How can i take attributes.blabla as string list?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The main point is that reqList is not IEnumerable in your code. Just change the signature to List of dynamics.

List<dynamic> reqList= new List<dynamic>();
reqList.Add(new{ attributes = new{blabla = "qq"}});

List<string> blablaList = reqList.Select(x => x.attributes.blabla as string).ToList();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading