How to create a list of num from 1 to 10 Example:
int[] values = Enumerable.Range(1,max).ToArray();
MessageBox.Show(values+",");
The output should be: 1,2,3,4,5,6,7,8,9,10 Please help
How to create a list of num from 1 to 10 Example:
int[] values = Enumerable.Range(1,max).ToArray();
MessageBox.Show(values+",");
The output should be: 1,2,3,4,5,6,7,8,9,10 Please help
your code is generating array of integers from 1 to 10
int[] values = Enumerable.Range(1,10).ToArray();
but you're displaying them in wrong way (you're trying to cast int array to string), change it to
MessageBox.Show(string.Join(",", values);
string.Join
will join your values separating them with ,
In .Net <4.0 you should use (and I believe OP is using one)
MessageBox.Show(string.Join(",", values.Select(x=>x.ToString()).ToArray());
Try like below using the generic version of Join<T>()
method.
int[] arr = Enumerable.Range(1, 10).ToArray();
MessageBox.Show(string.Join<int>(",", arr));
Generate 1,2,3,4,5,6,7,8,9,10
(OR) using good old foreach
loop
string str = string.Empty;
foreach (int i in arr)
{
str += i.ToString() + ",";
}
MessageBox.Show(str.TrimEnd(','));