With an ASP.NET MVC project I'm working on, I am required to check whether bit variables within a LINQ-To-SQL class are true. So far, After checking whether or not each variable is true or false, I then push the value of the field into a List and return it like so:
public List<String> GetVarList() {
List<String> list = new List<String>();
if (fields.SearchBar) {
list.Add("SearchBar");
}
if (fields.SomeField) {
list.Add("SomeField");
}
return list;
}
This, to me, doesn't seem to be the fastest or easiest way to do it.
I was wondering its possible to somehow be able check the value of the variable dynamically from an array of strings by looping through them with either a for or a foreach loop. For instance:
public List<String> GetVarList() {
String[] array = {"SearchBar", "SomeField"};
List<String> list = new List<String>();
foreach (String field in array) {
// Check whether or not the value is true dynamically through the array
}
return list;
}
Thanks for any suggestions!