title: How to sort items in a list using foreach C#
body: <p>I need to sort the items I have in a list by age using foreach in ascending order, and so I have no idea how to. This is my code so far:</p>
  
  <pre><code>namespace ListProject
  {
      public struct FamilyMem
      {
          public string name;
          public int age;
  
          public FamilyMem(string name,int age)
          {
              this.name = name;
              this.age = age;
          }
      }
  
      class Program
      {
          static void Main(string[] args)
          {
              FamilyMem Jack = new FamilyMem("Jack", 15);
              FamilyMem Tom = new FamilyMem("Tommy", 24);
              FamilyMem Felix = new FamilyMem("Felix", 26);
              FamilyMem Lukas = new FamilyMem("Lukas", 26);
              FamilyMem Austin = new FamilyMem("Austin", 54);
              FamilyMem Ben = new FamilyMem("Ben", 55);
  
              List&lt;FamilyMem&gt; gambleList = new List&lt;FamilyMem&gt;();
  
              gambleList.Add(Jack);
              gambleList.Add(Tom);
              gambleList.Add(Felix);
              gambleList.Add(Lukas);
              gambleList.Add(Austin);
              gambleList.Add(Ben);
  
              Console.WriteLine(gambleList.Count.ToString());
  
  
          }
      }
  } 
  </code></pre>
  
  <p>I also need a separate piece of code that will allow me to sort the names alphabetically. Thanks. </p>