070-573 Free Dumps Study Materials
Question 14: You have a Web Part that contains the following code segment. (Line numbers are included for
reference only.)
01 protected void Page_Load(object sender, EventArgs e)02 {
03 SPSite site = new SPSite("http://www.contoso.com/default.aspx");
04 {
05 SPWeb web = site.OpenWeb();
06
07 }
08 }
You deploy the Web Part to a SharePoint site.
After you deploy the Web Part, users report that the site loads slowly. You need to modify the Web
Part to prevent the site from loading slowly.
What should you do?
A. Add the following line of code at line 06:
web.Close();
B. Add the following line of code at line 06:
web.Dispose();
C. Add the following line of code at line 06:
site.Close();
D. Change line 03 to the following code segment:
using (SPSite site = new SPSite("http://www.contoso.com/default.aspx"))
Correct Answer: D
Explanation:
MNEMONIC RULE: "using statement"
You can automatically dispose SharePoint objects that implement the IDisposable interface by using
the Microsoft Visual C# and Visual Basic using statement.
Disposing Objects http://msdn.microsoft.com/en-us/library/ee557362.aspx