You can also use methods to set or just use properties!

Just like you can have a method read a variable and return it, you can also use a method to set its value:

public void SetQuestion(string question)
    this.question = question;

Or just use a property! Visual studio allows you to select the text, press Ctrl + . and then while having the variable selected, just click on “Encapsulate” to have something like this:

public string Question { get => question; set => question = value; }
1 Like

Privacy & Terms