title: Circular lists in C#
body: <p>I am not very experienced with C#. I am trying to build circular lists and I have done it like this:</p>
  
  <pre><code>public List&lt;string&gt; items = new List&lt;string&gt; {"one", "two", "three"};
  private int index = 0;
  
  void nextItem() {
      if (index &lt; items.Count - 1)
          index += 1;
      else
          index = 0;
  
      setItem();
  }
  
  void previousItem() {
      if (index &gt; 0)
          index -= 1;
      else
          index = items.Count - 1;
  
      setItem();
  }
  
  void Update() {
           if (Input.GetKeyDown(KeyCode.RightArrow)) nextItem();
      else if (Input.GetKeyDown(KeyCode.LeftArrow))  previousItem();
  }
  </code></pre>
  
  <p>But now I am wondering: Am I reinventing the wheel? Does C# already come with a proper data structure for this?</p>
  
  <p>EDIT: In case some context is needed. I have a game menu, where I display a collection of items, and I want that when I press "next" and Im at the last one, to show the first item again.</p>