How to print the contents of an array to a label in C #
I want to display the contents of an array with a semicolon between each number. num1 - num6 are integer variables converted from text fields. So far I have done this.
int[] number = new int [6] {num1, num2, num3, num4, num5, num6};
Array.Sort(number);
lblAnswer3.Text = number.ToString();
The output of this code is: System.Int32 []
I would like the result to be as follows: num1, num2, num3, num4, num5, num6 in ascending order.
+3
source to share
2 answers
You can easily concatenate IEnumerables and arrays using string.Join :
lblAnswer3.Text = string.Join(", ", number);
+4
source to share