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#

Recommended Answers

All 4 Replies

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

commented: 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

oh Mitja You solved this problem

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.