Click here to Skip to main content
14,879,491 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my WPF application, I have a MessageBox which is supposed to show
"your lucky numbers are i and j"

(where i and j are some numbers present in the local variables of integer type)

This is my code,

MessageBox.Show(string.Format("your lucky numbers are", i + 1, "and", j + 1));

Any help would be much appreciated. thanks
AditSheth 12-Sep-11 8:52am
just Simply put "your lucky number are" + (i+1).ToString() + " and " + (j+1).ToString()); instead of using string.Format
Wayne Gaylard 12-Sep-11 9:43am
Using string.Format is the recommended solution rather than concatenating strings like you suggested. That is what string.Format is there for.

1 solution

Try this:-

MessageBox.Show(string.Format("your lucky numbers are{0} and {1}", (j + 1).ToString(), (i + 1).ToString()));

Hope this helps
steersteer 12-Sep-11 8:44am
Wayne Gaylard 12-Sep-11 8:48am
No problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900