1

I have created a string array named 'coin' and I am trying to output the content of the string array to a item box along with another integer variable, and I keep getting the list box saying String[] Array.

To create the array, I have used the following:

string[] coins = new string[4];

Then on the click of the enter button, a new item will be added to the array, along with the count variable which increments on the click of the button, then it outputs the contents of the coin array to the list box:

coins[valuesEntered] = "coin" + valuesEntered.ToString();
valuesEntered++;
listBox1.Items.Add(coins);

However, this seems not to work and instead just outputs String[] Array to the group box each time the enter button is clicked. I cant seem to get past this brick wall at the moment.

2
  • 1
    You are trying to add the whole array each time. Try listBox1.Items.Add(coins[valuesEntered]) before you increment valuesEntered. Commented Dec 2, 2015 at 17:04
  • Thanks for your input, that doesn't work I'm afraid. It still outputs the same. Commented Dec 2, 2015 at 17:10

1 Answer 1

1

You are attempting to add an object to your ListBox, specifically a string array represented in syntax as String[] Array. You want the contents of the array, not the array itself.

You first need to join the individual contents of the array to a separate string variable before you attempt to add it to the ListBox.

string listOfCoins = string.Join(" ",coins);
listBox1.Items.Add(listOfCoins.ToString());

this might work too

listBox1.Items.Add(coins.Text);

I don't use Visual C# much, so take this with a grain of salt.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, I worked it out in the end, it was your solution which worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.