More elegant way to update index into circular list?

c#

Solution

I have a strong aversion to using `++` on a variable and then that variable again in the same statement. I believe this line works fine in C#, but lines like this are undefined in C/C++, and so they raise a flag for me. I would prefer

CurrentQuestion = (CurrentQuestion+1) % questions.Length;

Which I think of as the idiomatic way of doing clock-arithmetic in C-like languages.

Problem

I have a list of questions that the user will iterate through, they can start at any question, but they do have a order to them, so in order to do this I just maintain an index into the array and increment it like so: ``` CurrentQuestion = (++CurrentQuestion < questions.Length) ? CurrentQuestion : 0; ``` It isn't necessarily obvious what is happening here, is there a more elegant way to do this?

Original source