Split out ints from string

前端 未结 13 1504
情歌与酒
情歌与酒 2021-01-17 17:45

Let\'s say I have a web page that currently accepts a single ID value via a url parameter:
http://example.com/mypage.aspx?ID=1234

I want to change it to acce

13条回答
  •  猫巷女王i
    2021-01-17 18:15

    If you like the functional style, you can try something like

        string ids = "1,2,3,4,5";
    
        List l = new List(Array.ConvertAll(
            ids.Split(','), new Converter(int.Parse)));
    

    No lambdas, but you do have Converters and Predicates and other nice things that can be made from methods.

提交回复
热议问题