What’s the difference (CPU usage, MSIL, etc) between:
StreamWriter sw = new StreamWriter("C:\test.txt");
and:
StreamWriter sw = File.CreateText("C:\test.txt");
?
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.
Not much… (via Reflector)
For what it’s worth though I prefer using File.* factory methods because I think they look cleaner and are more readable than passing a bunch of constructor parameters to Stream or StreamWriter because it’s hard to remember which overloads do what if you’re not looking at the definition.
Also, JIT compilation will almost certainly inline the call anyway so even the miniscule overhead of a single additional method call will likely not be incurred.