tags:

views:

380

answers:

4

than just to call the parameter as it is?

+25  A: 

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();)
Marc Gravell
A: 

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.

BeowulfOF
A: 

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.

Daok
Guess you mean CLR.
Brian Rasmussen
+1  A: 

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.

Kris
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
@Brian: That is what Kris said. No.
Geoffrey Chetwood
Actually, Not only did I say No, I made a big point of saying no.
Kris
@Kris: Yay for reading comprehension, eh?
Geoffrey Chetwood