Lasse Edsvik
Lasse Edsvik

Reputation: 9298

Checkbox string[] to int[]

I have a asp.net mvc page with an array of checkboxes that gets posted to an insert-method.

And I have this string[] UsergroupIDs, that gets mapped properly, but it contatins "false"-values, and is in string[].

Is there some easy way of cast it to int[] and remove the "false"-values?

Using the .Select and .Where if possible? :)

/M

Upvotes: 1

Views: 309

Answers (1)

Konrad Rudolph
Konrad Rudolph

Reputation: 546045

First, filter the false values. Then parse them:

var intValues = stringValues.Where(x => x != "false").Select(x => int.Parse(x));

Upvotes: 3

Related Questions