Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

How could I improve getting a List based on the state of a checkbox?

$
0
0

I have 6x checkboxes, which represent filters and are booleans. These filters type are represented by an enum. I need to get a List depending on the state of the checkboxes and I'm trying to do it the right way.

Currently I have my 6x checkboxes, which are all boolean:

bool checkbox1Filter1bool checkbox2Filter2//...

I have an enum which looks like this with 6x values:

public enum MyFilters : byte{    Filter1 = 12,    Filter2 = 30,    // ...}

I currently have a function which adds my filters in a list depending on the state of the checkboxes:

function List­<MyFilters> GetMyFilters(){    var lst = new List<MyFilters>();    if (checkbox1Filter1) { lst.Add(MyFilters.Filter1) }    if (checkbox2Filter2) { lst.Add(MyFilters.Filter2) }    // ...    return lst;}

Basically I would like to completely get rid of that function and do something smarter with less 'if' everywhere. Could a Dictionary<MyFilters,bool> do the trick ?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>