Although each one differs from which method initializes the variable first, does it make a difference on performance or does it matter which one you use?
Date: 03 Mar 2013 00:22
Number of posts: 3
RSS: New posts
An excellent question. The answer is no. There's no difference on performance. In fact, out vs. ref is a C# specific thing, not a .NET framework thing, really. Regardless of which one you use, you get the same compiled code. There's no performance differences or any difference, once you get past the C# compiler.
The out and ref keywords are just C#'s way of trying to enforce certain common programming idioms. out is for times where you're saying, "I have this bucket that I want to to put stuff in. Make sure it gets put there. (And I don't care if you get rid of/overwrite what's already there.)" It's an output parameter. ref is for times where you're saying, "I have this bucket. I want you to use my bucket. Not dump the stuff out of it and put it in your own bucket."