than just to call the parameter as it is?
-
Where did you hear this? – Michael Haren Dec 09 '08 at 13:50
-
I too want to know where you heard this. – Kris Dec 09 '08 at 13:54
-
My guess would be from a colleague who wanted to scare this person out of ever using 'this' again. It can be fairly annoying when someone uses 'this' for every single thing they do. Not that it justifies lying to a new programmer, but I can imagine someone doing this out of frustration. – GEOCHET Dec 09 '08 at 13:56
-
I don't mind seeing "this." used when it's not strictly necessary. It explicitly says to a program maintainer what your intentions are. If you have to spread FUD about its use, then it must not be that bad. (I'm not pointing fingers at anyone here, just saying in general.) – Bill the Lizard Dec 09 '08 at 14:37
4 Answers
If you mean fields, then no. The compiler injects "this" (ldarg.0) whether you use it explicitly (this.foo) or implicitly (foo).
It does, however, take 5 more characters in your source code... so a handful of bytes on your development hard disk. It will make exactly zero difference in the compiled IL or at runtime.
There are two scenarios where use of "this" changes things:
- when there is a variable/parameter with the same name (
this.foo = foo;
) - when resolving extension methods (
this.SomeMethod()
;)

- 1,026,079
- 266
- 2,566
- 2,900
Your question is much too ambiguous to answer definitively but i would still start with a resounding No
then i'd want to know what exactly do you mean with parameter? I would normally interpret it as "argument to a method" but they are not tied to "this" within scope so you probably meant "members" such as fields, properties and/or methods.
If all of my assumptions about how to interpret your question are correct, I stand by my former "No".
But i would like to know where you got that idea from.

- 40,604
- 9
- 72
- 101
-
The question may be ambiguous, but I still can't think of any situations in which this would require more memory. Could you elaborate please? – Brian Rasmussen Dec 09 '08 at 13:46
-
-
I do not know, if it uses more memory, but I don't think so, its only a clear reference, something that would be done under the hood as well by the compiler.

- 9,018
- 9
- 42
- 48
I guess you mean before the variable name? I do not see why it would use more memory. The CLR must be optimize whatever the syntax is to refer to the variable to a way that it doesn't affect the performance (after verification, it will add the this...). So no it doesn't.

- 136,852
- 88
- 292
- 341