Prodigy Prodigy - 1 month ago 5
C# Question

Trying to display an array of numbers onto label

private static void Display(params Object[] things)
{
foreach (Object num in number)
Label5.Text = "{0} ", + num;
}


I'm not really sure what to really do. I want to display all the input numbers onto
label5
, but I'm not really sure how to do it.

For example: I have a
textBox
and the user enters in
23, 50, 89, 73, 40
, etc into the
textBox
and I want to display the numbers the user entered into
label5
. Thank you.

Answer

If you want to display the text a user has entered into a textbox, why not assign it directly

label5.Text = textbox.Text; 

The way you want to do it, to set it from an array you can do it like this:

private static void Display(params Object[] things)
{
    foreach (Object num in number)
       Label5.Text = Label5.Text + String.Format("{0}, " + num);
}

I don't quite understand though why you pass an array ob objects into the method if you don't use them.

Comments