0

Primary List:

enum CarMake
{
   Ford, Toyota, Honda
}

Secondary List:

enum CarModel
{
  Explorer, // Ford
  Corolla, // Toyota
  Camry, // Toyota
  Civic, // Honda
  Pilot //  Honda

}

Is there some means of linking the 2 enum lists together?

So that when using CarMake the program will know which CarModels are linked?

John M
  • 14,338
  • 29
  • 91
  • 143

2 Answers2

1

No, as you want to achieve is not possible, but it would be possible using Dictionaries and string for CarModel

var dict = new Dictionary<CarMake,string[]>();

dict.Add(CarMake.Ford, new string[] { "Explorer" });
dict.Add(CarMake.Toyota, new string[] { "Corolla","Camry" });
dict.Add(CarMake.Honda, new string[] { "Civic","Pilot" });

then if you want to retrieve the cars from Honda, you call it as shown below:

var hondaCars = dict[CarMake.Honda]

If you, instead, want to retrieve the car-maker from the model you just call:

var carMaker = dict.FirstOrDefault(key => key.Value.Contains("Civic")).Key
Michael Mairegger
  • 6,833
  • 28
  • 41
0

You might wanna look into this.

Combine multiple enums into master enum list

allCars.AddRange(Enum.GetValues(typeof(CarModel)).Cast<Enum>());
allCars.AddRange(Enum.GetValues(typeof(CarMake)).Cast<Enum>()); 

Since if you make the list carModel into a master list in theory you get your answer

Community
  • 1
  • 1
MikeBroski
  • 64
  • 1
  • 8