Link to home
Start Free TrialLog in
Avatar of Miguel Oz
Miguel OzFlag for Australia

asked on

LINQ group by enum and map to another enum

Dear Experts:
I need to group a list of customers (List<Customer>) where Customer contains this enum

public enum CustomerType
{
  type1,
  type2,
  type3,
  type4,
  type5
}

Open in new window


to a new enum
public enum NewCustomerType
{
  newtype1,  //map to type1
  newtype2,  //map to type2 and 3
  newtype3,  //map to type4 and 5 
}

Open in new window


Note: My initial code to map to the first enum:
var sortedDetails = _customers.GroupBy(x => x.CustomerType).ToDictionary(t => t.Key, t => t.ToList());
Your answer should return a dictionary mapped to the new enum.

Thanks
Avatar of kaufmed
kaufmed
Flag of United States of America image

What is the point of this code? I get that you want to remap the customer type, but what is the purpose of the GroupBy?
Avatar of Miguel Oz

ASKER

If you are refering to the initial code sample is just to show you an initial attempt,. My expectations is that your answer should provide me with a dictionary sorted by the new enum.
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks