string.Concat & MessageBox
-
I need to pass a few strings & vars to MessageBox. The following works, but is there a better way than creating the object?
Object[] warning = new Object[] { "File " fileName " needed from " fileLocation " is missing." };
MessageBox.Show(string.Concat(warning));Thanks.
-
I need to pass a few strings & vars to MessageBox. The following works, but is there a better way than creating the object?
Object[] warning = new Object[] { "File " fileName " needed from " fileLocation " is missing." };
MessageBox.Show(string.Concat(warning));Thanks.
MessageBox.Show("File " +fileName+ " needed from " +fileLocation+ " is missing.");
:doh:
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
-
I need to pass a few strings & vars to MessageBox. The following works, but is there a better way than creating the object?
Object[] warning = new Object[] { "File " fileName " needed from " fileLocation " is missing." };
MessageBox.Show(string.Concat(warning));Thanks.
Look into
String.Format
. You can rewrite your message like this:String warning = String.Format("File {0} needed from {1} is missing.", fileName, fileLocation);
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
MessageBox.Show("File " +fileName+ " needed from " +fileLocation+ " is missing.");
:doh:
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
-
Look into
String.Format
. You can rewrite your message like this:String warning = String.Format("File {0} needed from {1} is missing.", fileName, fileLocation);
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
I need to pass a few strings & vars to MessageBox. The following works, but is there a better way than creating the object?
Object[] warning = new Object[] { "File " fileName " needed from " fileLocation " is missing." };
MessageBox.Show(string.Concat(warning));Thanks.
Better yet, put your string in a resource dictionary, in the format File {0} needed from {1} is missing.. Then, in your code retrieve it and format it using
string format=string.Format(resourceText, fileName, fileLocation);
The advantage of doing this is that you can easily localise your applications by doing this - the
{0} {1}
can be rearranged in different languages as appropriate so the text will be displayed in the format the user would expect."WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
Better yet, put your string in a resource dictionary, in the format File {0} needed from {1} is missing.. Then, in your code retrieve it and format it using
string format=string.Format(resourceText, fileName, fileLocation);
The advantage of doing this is that you can easily localise your applications by doing this - the
{0} {1}
can be rearranged in different languages as appropriate so the text will be displayed in the format the user would expect."WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.