Lesson 23 Ex. 1 (Complex Numbers)
I was reviewing this example for a little bit until the hint finally clicked. I opened the books code to help understand what was happening. The methods make sense, however something else caught my eye.
ComplexNumber class's methods, AddTo for example
public ComplexNumber AddTo(ComplexNumber c1)
ComplexNumber result = new ComplexNumber();
result.Real = this.Real + c1.Real;
result.Imaginary = this.Imaginary + c1.Imaginary;
I dont really understand the "this" keyword very well. and in this example I removed all the "this" keywords and it still worked perfectly. IE remove this.Real and turn it to just Real.
From what I do understand of (this), it represents the current object in the code that is executing. So this would usually just represent a class, and represent all of its fields or parameters. But I'm confused on why it would be used in this example?