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

.ToString().ToList() returns a New List<char>

So I have a Query that searches for various items. But I just want their Id so I used a projection to return me only the Ids and not the other elements of the item. but converting from ObjectId .ToString() and then .ToList() returns me a List<char> instead List<string>

var items = await this.ItemAppService.GetAllAsync(expression,
               x => new
               {
                  Ids = x.Id.ToString().ToList(),
               });
           var Ids = items.SelectMany(x => x.Ids.Select(x => x)).ToList();

I would like to understand why i’m returning a List<Char> and how I convert it to List<String>

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 first ToList is unnecessary, you want strings, and with that ToList() invocation you are converting your strings to char arrays. So the code should be rewritten as:

var items = await this.ItemAppService.GetAllAsync(expression,
    x => new
    {
        Id = x.Id.ToString(),
    });
var ids = items.Select(x => x.Id).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