Reputation: 9298
I'm using mvc and I'm trying to loop through a array of checkboxes, but how do I exclude the ones that are "false" in that list?
for(int i = 0; i < TimeRange1.Length; i++)
{
if(TimeRange1[i] == "false" ....??)
// dostuff
}
or is there some better way of doing it?
/M
Upvotes: 0
Views: 143
Reputation: 8966
Assuming TimeRange1
is your CheckBox[]
, try this:
for (int i = 0; i < TimeRange1.Length; i++)
{
if (TimeRange1[i] == "on")
{
// dostuff
}
}
Upvotes: 1
Reputation: 191036
Since you are doing it with MVC - you could make TimeRange1
a bool[]
.
Then, you could always do this with linq
var newItems = TimeRange1.Select(i => i == false);
foreach(var item in newItems)
{
....
}
or you could simplify it
foreach(var item in TimeRange1.Select(i => i == false))
{
....
}
Upvotes: 1