What is the best practice way to get all items from SPList(with query or without)
This is my ways :
static void Main(string[] args)
{
try
{
using (SPSite mySite = new SPSite("http://sf-spsdev04/sites/gkk92"))
{
using (SPWeb myWeb = mySite.OpenWeb())
{
SPList myList = myWeb.Lists["Employees"];
SPListItemCollection myItems = myList.GetItems();
//1st way
foreach (SPListItem item in myItems)
{
Console.WriteLine(item["Title"]);
}
//2nd way
foreach (SPListItem item in myList.GetItems())
{
Console.WriteLine(item["Title"]);
}
//3th way
foreach (SPListItem item in myWeb.Lists["Employees"].Items)
{
Console.WriteLine(item["Title"]);
}
}
}
}
catch(Exception ex)
{
throw new Exception(ex.ToString());
}
What are yours ?