Wacku
Wacku
CC#
Created by Wacku on 3/19/2024 in #help
Is there a better way to do this? (multiple switch statements with repetitive names)
Hey there, I'm new to C#, so forgive me if this question seems a bit stupid. To Explain, these are lists ObservableCollection lists. if a list has no items, it is not added to the master list. each switch case validates whether or not to add the list. In the actual application there are 20 lists, but I have included 3 of the statements because they are all the same. If I am not being clear enough, please let me know, Thank you.
switch (group1.Items.Count)
{
case 0:
break;
default:
this.AllGroups.Add(group1);
break;
}
switch (group2.Items.Count)
{
case 0:
break;
default:
this.AllGroups.Add(group2);
break;
}
switch (group3.Items.Count)
{
case 0:
break;
default:
this.AllGroups.Add(group3);
break;
}
switch (group1.Items.Count)
{
case 0:
break;
default:
this.AllGroups.Add(group1);
break;
}
switch (group2.Items.Count)
{
case 0:
break;
default:
this.AllGroups.Add(group2);
break;
}
switch (group3.Items.Count)
{
case 0:
break;
default:
this.AllGroups.Add(group3);
break;
}
7 replies