locked
MessageBox.Show multiple methods RRS feed

  • Question

  • I am writing a program that takes in input and outputs it using messagebox.show

    I can get one string method to show in the message box, but I cannot get the other methods to populate.

    Tried using this code  

    MessageBox.Show(h.LastName, h.Gender)

    but it only shows LastName.

    What am I missing from the code?   I thought a comma would be enough to get both methods to show.

    • Moved by CoolDadTx Tuesday, September 23, 2014 2:41 PM Winforms related
    Monday, September 22, 2014 4:02 AM

Answers

  • As you have written it, the first string will be the main text, the second string will be the caption (heading).

    If you want both strings to go into the text, you need to concatenate them into one string.

    MessageBox.Show(h.LastName + " " + h.Gender);
    • Proposed as answer by CoolDadTx Tuesday, September 23, 2014 2:40 PM
    • Marked as answer by Barry Wang Tuesday, October 7, 2014 9:39 AM
    Monday, September 22, 2014 4:11 AM

All replies

  • As you have written it, the first string will be the main text, the second string will be the caption (heading).

    If you want both strings to go into the text, you need to concatenate them into one string.

    MessageBox.Show(h.LastName + " " + h.Gender);
    • Proposed as answer by CoolDadTx Tuesday, September 23, 2014 2:40 PM
    • Marked as answer by Barry Wang Tuesday, October 7, 2014 9:39 AM
    Monday, September 22, 2014 4:11 AM
  • When you use a comma you want to make objects separately, right? please think about a collection if want to get members' value you must do it member by member.

    If you want to do one time, you must combine them into one object so the operator "+" is the right solution.

    Monday, September 22, 2014 4:35 AM
  • Ok that works for me. 

    Why is it that I cannot concatenate a method with that?

    Monday, September 22, 2014 5:14 AM
  • Nevermind.  I found out a way to do it.

    Thank you for the help.

    Monday, September 22, 2014 5:17 AM
  • Would you mind letting us know the result of the suggestion? It could be better to help someone meet the same issue.Thanks



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, September 23, 2014 8:47 AM