Integer to Integer Array C#

前端 未结 14 1579
深忆病人
深忆病人 2020-12-08 04:42

I had to split an int \"123456\" each value of it to an Int[] and i have already a Solution but i dont know is there any better way : My solution was :

publi         


        
14条回答
  •  无人及你
    2020-12-08 05:39

    Thanks to ASCII character table. The simple answer using LINQ above yields answer + 48.

    Either

    int[] result = youtInt.ToString().Select(o => Convert.ToInt32(o) - 48).ToArray();
    

    or

    int[] result = youtInt.ToString().Select(o => int.Parse(o.ToString())).ToArray();
    

    can be used

提交回复
热议问题