Something so simple, but my head is hurting over it, I’m sure I can write this in one line when converting, but how?
IQueryable<ion> ions =FindAllions();
List<ionFormViewModel> ionFormViewModels = new List<ionFormViewModel>();
foreach (ion ion in ions)
{
ionFormViewModel ionFormViewModel = new ionFormViewModel(ion);
ionFormViewModels.Add(ionFormViewModel);
}
Try this:
The
Enumerable.Selectextension method allows you to project a new value into a new sequence for each value in your current sequence. Basically it gives you the ability to generate sequences from other sequences with a transformation step in between.Then the
Enumerable.ToListextension method simply creates a newList<T>from theSelectmethod’s resultingIEnumerable<T>.