convert string[] to int[]

后端 未结 7 920
一个人的身影
一个人的身影 2020-12-18 22:38

Which is the fastest method for convert an string\'s array [\"1\",\"2\",\"3\"] in a int\'s array [1,2,3] in c#?

thanks

7条回答
  •  误落风尘
    2020-12-18 23:29

    The is no fast way I know but you can use a "short way":

    var numbers = new[] {"1", "2", "3"};
    
    var result = numbers.Select(s => int.Parse(s));
    int[] resultAsArray = result.ToArray();
    

    And if you use PLink you get to compute the values in parallel.

提交回复
热议问题