开发者

Checkbox string[] to int[]

开发者 https://www.devze.com 2022-12-19 17:25 出处:网络
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

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 "开发者_如何学Gofalse"-values?

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

/M


First, filter the false values. Then parse them:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号