Having this code:
using (BinaryWriter writer = new BinaryWriter(File.Open(ProjectPath, FileMode.Create)))
{
//save something here
}
Do we need to close the BinaryWriter? If not, why?
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.
So long as it’s all wrapped up in a
usingblock then you don’t need to explicitly callClose.The
usingblock will ensure that the object is disposed, and theCloseandDisposemethods are interchangeable onBinaryWriter. (TheClosemethod just callsDisposebehind the scenes.)