Use this. to access internal class members?

Posted by Sam on Stack Overflow See other posts from Stack Overflow or by Sam
Published on 2010-03-17T09:32:02Z Indexed on 2010/03/17 9:41 UTC
Read the original article Hit count: 158

Filed under:
|
|

On the internet I see a lot of code which uses this. to access local members of a class, like this:

private String _whatever;
public String Whatever
{
  get
  {
    return this._whatever;
  }
  set
  {
    this._whatever = value;
  }
}

public void DoSomething()
{
  String s = this.Whatever;
  this.DoSomething();
}

(don't expect the code to do something sensible. I just wanted to show a few different uses for "this.")

I wonder why to do this? To add more clarity to the source?
Or is it just a waste of space?

© Stack Overflow or respective owner

Related posts about c#

Related posts about this