Currently have the below code which upon compilation creates an anonymous list. I need to convert that to a standard list type preferably a dictionary. I can't find anything online to do so.
_dbService.GetAllOrN().Select(x => new { x.Id, x.Name});
Currently have the below code which upon compilation creates an anonymous list. I need to convert that to a standard list type preferably a dictionary. I can't find anything online to do so.
_dbService.GetAllOrN().Select(x => new { x.Id, x.Name});
LINQ has ToDictionary
. You could do that instead of calling Select
.
.ToDictionary(x => x.Id, x => x.Name);