title: C# Sorting a List of an Object which contains another List of an Object
body: <p>Ok, I'm looking to sort the List (UserList) by the property (WordList), although I need (WordList) to be sorted by a particular property first.</p>
  
  <p>The whole Sort UserList method does not sort the UserList whether I try by (userName) or by the (WordList).(wordName) or (WordList).(amountOfGuesses)</p>
  
  <pre><code>public class User
  {
      public string userName;
      public List&lt;Word&gt; wordList;
  
      public User() { }
  
      public User(string name, String word, int guesses)
      {
          this.userName = name;
          wordList = new List&lt;Word&gt;();
          Word theWord = new Word(word, guesses);
          this.wordList.Add(theWord);
      }
  }
  
  public List&lt;User&gt; SortUserList(String g) 
      {
          String option = g.ToLowerInvariant();
          switch(option){
              case "name":
                  this.UserList.OrderBy(x=&gt; x.userName);
                  break;
              case "word":
                  this.UserList.OrderBy(k =&gt; k.wordList.OrderBy(w =&gt; w.wordName));
                  break;
              case "guess":
                  this.UserList.OrderBy(m=&gt; m.wordList.OrderBy(y =&gt; y.amountOfGuesses));
                  break;
          } 
          return UserList;
      }
  
      public void Test()
      {
          User xor = new User("xor", "xadfs", 20);
          User bob = new User("bob", "char", 3);
          User james = new User("james", "adfsad", 200);
          UserList.Add(bob);
          UserList.Add(james);
          UserList.Add(xor);
      }
  </code></pre>