Complete the code to print the current object's name using this keyword.
public class Person { public string Name; public void PrintName() { Console.WriteLine(this.[1]); } }
The this keyword refers to the current object instance. To access the Name field, use this.Name.
Complete the constructor to assign the parameter to the instance variable using this keyword.
public class Car { public string Model; public Car(string model) { this.[1] = model; } }
The instance variable is Model. Use this.Model to refer to it and assign the parameter model.
Fix the error by completing the method to return the current object's description using this keyword.
public class Book { public string Title; public string GetDescription() { return this.[1]; } }
this alone which is not a string.The field is named Title with uppercase T. Use this.Title to access it correctly.
Fill both blanks to create a method that compares the current object's age with another object's age using this keyword.
public class Animal { public int Age; public bool IsOlderThan(Animal other) { return this.[1] [2] other.Age; } }
other on the left side instead of this.Use this.Age to get the current object's age and compare it with other.Age using the greater than operator >.
Fill all three blanks to create a method that updates the current object's score only if the new score is higher, using this keyword.
public class Player { public int Score; public void UpdateScore(int newScore) { if (newScore [1] this.[2]) { this.[3] = newScore; } } }
newScore instead of this.Score.The method checks if newScore is greater than this.Score. If yes, it updates this.Score to newScore.