If we are not performing
any operations on the SPSite object, we can write as in the following code
example.
void CombiningCallsBestPractice()
{
using (SPSite siteCollection = new
SPSite(SPContext.Current.Web.Url))
using (SPWeb web = siteCollection.OpenWeb())
{
//Perform operations on site.
} // SPWeb object web.Dispose()
automatically called; SPSite object
//
siteCollection.Dispose() automatically called.
}
No comments:
Post a Comment