How to convert int array to int?

前端 未结 12 2088
小蘑菇
小蘑菇 2021-01-18 07:49

What I would like to learn how to do is to convert an int array to an int in C#.

However I want to append the int with the values from the array.

Example:

12条回答
  •  忘掉有多难
    2021-01-18 08:20

    Another simple way:

    int[] array =  {5, 6, 2, 4};
    int num;
    if (Int32.TryParse(string.Join("", array), out num))
    {
        //success - handle the number
    }
    else
    {
        //failed - too many digits in the array
    }
    

    Trick here is making the array a string of digits then parsing it as integer.

提交回复
热议问题