convert char array to int array c#

后端 未结 6 1016
抹茶落季
抹茶落季 2021-01-01 22:45

I have this array

char[] A = [\'1\', \'2\', \'3\', \'4\']

And I want to convert it to int[]

int[] Aint=[1, 2, 3, 4]
         


        
6条回答
  •  臣服心动
    2021-01-01 22:58

    Add a using statement for using System.Linq; then you can do the following:

    int[] Aint = A.Select(i => Int32.Parse(i.ToString())).ToArray();
    

    You will get an exception if an element in A cannot be parsed.

提交回复
热议问题