LINQ Sorting - First three need to be different manufacturers

Posted by Rob on Stack Overflow See other posts from Stack Overflow or by Rob
Published on 2010-03-19T04:43:33Z Indexed on 2010/03/19 4:51 UTC
Read the original article Hit count: 167

Filed under:
|
|

My OM has a 'product' object.
Each product has a 'manufacturer id' (property, integer).
When I have a list of products to display, the first three are displayed as the 'featured products'.
The list is already sorted in a specific sort order, putting the 'featured' products first in the list.

However, I now need to ensure the featured products in the listing are from different Manufacturers. I want to have a method to call to do this re-sorting. Trying to utilize LINQ to to the querying of the input 'products' and the 'results'

   public List<Product> SetFeatures(List<Product> products, int numberOfFeatures)
   {
       List<Product> result;

       // ensure the 2nd product is different manufacturer than the first ....

       // ensure the 3rd product is a different manufacturer than the first two... 

       // ... etc ... for the numberOfFeatures

       return result;

   }

Thanks in advance.

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ