I have a list of objects where one of the properties on the object class is an enum.
The program below simply loops through each item in the list, checks an int value, then checks the enum value for that item, then adds the item to another list when the condition is met.
I am using if-else statements, I attempted to use a switch statement but it doesn't seem possible to place 2 constants on a single case.
I'd like to know if there's a better / more elegant way to do this or is what I've done sufficient in this scenario?
Program Code
// User inputs number from 1 - 5
int SelectedOppType = Int32.Parse(Console.ReadLine());
foreach (Opportunities Opp in OpportunitiesList)
{
if (SelectedOppType == 1 && Opp.OpportunityStatusID == OpportunityStatus.Active) // Opp.OpportunityStatusID == OpportunityStatus.Draft
{
FilterdOppsList.Add(Opp);
}
else if (SelectedOppType == 2 && Opp.OpportunityStatusID == OpportunityStatus.Draft)
{
FilterdOppsList.Add(Opp);
}
else if (SelectedOppType == 3 && Opp.OpportunityStatusID == OpportunityStatus.Closed)
{
FilterdOppsList.Add(Opp);
}
else if (SelectedOppType == 4 && (Opp.OpportunityStatusID == OpportunityStatus.Active || Opp.OpportunityStatusID == OpportunityStatus.Draft))
{
FilterdOppsList.Add(Opp);
}
else if (SelectedOppType == 5)
{
FilterdOppsList.Add(Opp);
}
}
foreach (var OppItem in FilterdOppsList)
{
Console.WriteLine(OppItem.OppText);
}
Console.ReadLine();