When should the keyword 'this' be used within C# class definitions?
Is it standard to use the form "this.Method()" from within class? Or to just use "Method()"? I have seen both, and usually go with the second choice, but I would like to learn more about this subject.
Most of the time it is redundant and can be omitted; a few exceptions:
Foo() : this("bar") {}
this.foo = foo;
etcthis.SomeMethod();
(where defined as public static SomeMethod(this Foo foo) {...}
)Helper.DoSomething(this);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With