The common code to get data by itemcollections is by using SPListitems and using SPQuery for the query the data.
The common code is like this below :
SPWeb web = SPContext.Current.Web;
SPList list = web.List(“name of list”);
SPQuery query = new SPQuery (“xxx caml xxx”);
SPListItemCollection itemcols = list.getItems(query);
After this we can iterate using foreach or for to get data from itemscols.
But now we also can achieve this code with LINQ way and here as below the sample code :
SPListItemCollection itemcols = list.Items;
var latestItems = itemcols.Cast<SPListItem>().Where(p => p.Title != testTitle);
or you can also do like this as well :
var latestItems = itemcols.Cast<SPListItem>()
.Where(p => p.Title != testTitle)
.OrderByDescending(p => p[Constants.Modified].ToString())
Cool right! 🙂