title: c# Add custom method to Lists
body: <p>I would like to add a method to extend my List behavior, but I'm having trouble. I would like have the 'extension' method in the class where I'm working on it. How can I do it?</p>
  
  <p>I want to do:</p>
  
  <pre><code>class MyClass
  {
      public void DoSomething()
      {
          List&lt;string&gt; myList = new List&lt;string&gt;()
          myList.Add("First Value");
          myList.AddMoreValues(); //or myList += AddMoreValues()  ??
      }        
  
      private void AddMoreValues(this List&lt;string&gt; theList)
      {
          theList.Add("1");
          theList.Add("2");
          ...
      }
  }
  </code></pre>
  
  <p>The code above gives me the error:</p>
  
  <blockquote>
    <p>Extension method must be defined in a non-generic static class</p>
  </blockquote>