I'm wondering if there is a better way to do the following,
IList<RoleViewModel> ReturnViewModel = new List<RoleViewModel>();
IList<Role> AllRoles = PermServ.GetAllRoles();
foreach (var CurRole in AllRoles)
{
ReturnViewModel.Add(new RoleViewModel(CurRole));
}
Its pretty simple code simply taking the Data Object and converting it into a ViewModel. I was wondering if there was a way to do this better? - Maybe with Linq?
From the top of my head (not by dev machine).
IList<RoleViewModel> returnViewModel = PermServ.GetAllRoles()
.Select(x => new RoleViewModel(x))
.ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With