This is my code:
string data = "...";
var stream = new StreamReader(data);
Is that okay not call the Close() method?
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.
Have you actually compiled and run your code?
The
StreamReader(string)constructor treats the input as a file name!Unless this isn’t really your code and you meant
StringReader, your code is trying to stream the contents of the file name specified indata, which is likely to throw aFileNotFoundExceptionbecause the file probably doesn’t exist. And if it did, you would certainly need to callCloseor integrate your code into ausingstatement to release the file handle.