Option 2
You can wrap the logic in property as in this code.
IMO, this is bit more readable.
public class TestQuestion
{
private string _result;
public string Result
{
get
{
return _result;
}
set
{
_result = value;
this.CorrectCount += (this._result == Meta.correctResult ? Meta.incrementCount: 0);
this.IncorrectCount += (this._result == Meta.incorrectResult ? Meta.decrementCount : 0);
this.ShownCount += (this._result == Meta.shownResult ? Meta.incrementCount : 0);
}
}
public int CorrectCount;
public int IncorrectCount;
public int ShownCount;
}
Here is code for Meta
, this makes it easy to configure and control at one place.
public class Meta
{
public static string correctResult = "t";
public static string incorrectResult = "f";
public static string shownResult = "s";
public static int incrementCount = 1;
public static int decrementCount = -1;
}
This is how I used it in LinqPad
void Main()
{
TestQuestion testQuestion = new TestQuestion();
testQuestion.Result = "t";
testQuestion.Result = "f";
testQuestion.Result = "s";
testQuestion.Dump();
}
Isn't it more readable ?