title: How to return IGrouping from Linq query when grouping
body: <p>I am adding a bunch of different parts to a <code>List&lt;&gt;</code> and some of the part may have the same part number and the same length. If they do have the same partnumber and the same length I need to group those parts for displaying.</p>
  
  <p>When they're grouped I need to show that partnumber and how many of that partnumber with a specific length.</p>
  
  <p>I am needing to know how to group with two differnt properties and return eaigher a typed object with that <code>List&lt;ICutPart&gt;</code> and the total of </p>
  
  <p>Below is as far as I could get, I was attempting to return <code>(IGrouping&lt;int,ICutPart&gt;)sGroup;</code> but I am getting an error at the return portion of the function body.</p>
  
  <p>How can I return a typed object with <code>Group{List&lt;ICutPart&gt; Parts, Int Total}</code>?</p>
  
  <pre><code>    public class CutPart : ICutPart
  {
      public CutPart() { }
      public CutPart(string name, int compID, int partID, string partNum, decimal length)
      {
          this.Name = name;
          this.PartID = partID;
          this.PartNumber = partNum;
          this.CompID = compID;
          this.Length = length;
      }
      public CutPart(string name, int compID, int partID, string partNum, decimal width, decimal height)
      {
          this.Name = name;
          this.CompID = compID;
          this.PartNumber = partNum;
          this.PartID = partID;
          this.Width = width;
          this.Height = height;
          this.SF = decimal.Parse(((width / 12) * (height / 12)).ToString(".0000")); //2dp Number;
      }
  
      public string Name { get; set; }
      public int PartID { get; set; }
      public string PartNumber { get; set; }
      public int CompID { get; set; }
      public decimal Length { get; set; }
      public decimal Width { get; set; }
      public decimal Height { get; set; }
      public decimal SF { get; set; }
  }
  
  public class CutParts : List&lt;ICutPart&gt;
  {
  
      public IGrouping&lt;int, ICutPart&gt; GroupParts()
      {
  
          var sGroup = from cp in this
                       group cp by cp.Length into g
                       select new
                       {
                           CutParts = g,
                           total = g.Count() 
                       };
  
          return (IGrouping&lt;int, ICutPart&gt;)sGroup;
  
      }
  
  
      public new void Add(ICutPart item)
      {
          base.Add(item);
      }
  
  }
  </code></pre>