Always remember to avoid creating and destroying objects unnecessarily in code, as this may require that extra queries be made against the database.
In the following example, separate objects for the “Tasks” list must be instantiated each time the indexer is used to set properties and the method for updating is called. This is not a recommended practice.
SPWeb myWeb = SPContext.Current.Web;
myWeb.Lists["Tasks"].Title = "List_Title";
myWeb.Lists["Tasks"].Description = "List_Description";
myWeb.Lists["Tasks"].Update();
The following example instantiates the “Tasks” list object only once and assigns it to the myList variable in order to set properties and call the method.
SPWeb myWeb = SPContext.Current.Web;
SPList myList = myWeb.Lists["Tasks"];
myList.Title="List_Title";
myList.Description="List_Description";
myList.Update();
Bonus Tip:
To return a single item from a collection, always use a Get* method when one is provided through a parent object, instead of iterating through the entire collection and using an indexer. For example, the SPWeb class provides GetFile, GetFolder, and GetListItem methods that you can use to return single items.
9b293d66-341d-4210-9b1f-f26919176c29|0|.0