0

i make a string array and want to show in message box,but it does not working properly
Help Me what is wrong

private void btnarray_Click(object sender, EventArgs e)
        {
            string[] myname = new string[2];
            myname[0] = "Shahid";
            myname[1] = "Hussain";
            MessageBox.Show(myname.ToString());

        }

when message box show error show
Error is "System.string[]"
But it does not show myname one by one
YousafC#

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by yousafc#
1

Sure, you cannot show an array in a messageBox (its like putting a string array into stirng - cant do).
You have to get all values from an array into a string, then show it in messageBox:

string[] myname = new string[2];
            myname[0] = "Shahid";
            myname[1] = "Hussain";
            string items = null;
            for (int i = 0; i < myname.Length; i++)
                items += myname[i] + Environment.NewLine;
            MessageBox.Show("This is the list:\n" + items);

Hope it helps,
Mitja

Votes + Comments
He is best Developer
0

:) damn. I forget about it every time.
I will try to remember to use from now on in cases like this.
Thx momerath.

Mitja

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.