Actually this instruction is not C# originated. I know it was present in at least Python before that. The easiest way is to use a static local variable holding the last returned result and continue from there during the next call.

Qt Code:
  1. int getNextNatural(bool restart=false){
  2. static int last = -1;
  3. if(restart)
  4. last = -1;
  5. return ++last;
  6. }
To copy to clipboard, switch view to plain text mode