Select list from list c# code example
Example 1: select from list c#
Using System.Linq;
list.where(predicate);
list.select(predicate);
Example 2: select single item from list c#
using (var db = new ApplicationDbContext())
{
var file = db.Table
.Where(x => x.Id == id)
.Select( x => new itemModel
{
itemTest = x.itemTest,
}).ToList();
ModelList ML = new ModelList();
ML.ViewModelList = new List<ViewModel>();
foreach(var item in file)
{
ViewModel img = new ViewModel();
img.itemTest = item.itemTest;
ML.ViewModelList.Add(img);
}
var singleitem = ML.ViewModelList.Select(x => x.itemTest).LastOrDefault();
}