For example
using(var something = GetSomething())
{
something.DoSomething();
if(something.IsX()) return true;
}
return false;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, absolutely. The
Disposemethod is called however theusingstatement is executed, unless it was an abrupt whole-process termination. The most common cases are:returnwithin the blockBasically a
usingstatement is mostly syntactic sugar for atry/finallyblock – andfinallyhas all the same properties.EDIT: From section 8.13 of the C# 4 specification:
The
finallystatement is described in section 8.10 of the specification: