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";


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

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,

He is best Developer

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


This question has already been answered. Start a new discussion instead.