Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. string.Concat & MessageBox

string.Concat & MessageBox

Scheduled Pinned Locked Moved C#
question
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BDJones
    wrote on last edited by
    #1

    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.

    L D P 3 Replies Last reply
    0
    • B BDJones

      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.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      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


      B 1 Reply Last reply
      0
      • B BDJones

        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.

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        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...

        B 1 Reply Last reply
        0
        • L Luc Pattyn

          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


          B Offline
          B Offline
          BDJones
          wrote on last edited by
          #4

          Thank you.

          1 Reply Last reply
          0
          • D Dave Kreskowiak

            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...

            B Offline
            B Offline
            BDJones
            wrote on last edited by
            #5

            Thank you..

            1 Reply Last reply
            0
            • B BDJones

              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.

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              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.

              My blog | My articles | MoXAML PowerToys | Onyx

              B 1 Reply Last reply
              0
              • P Pete OHanlon

                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.

                My blog | My articles | MoXAML PowerToys | Onyx

                B Offline
                B Offline
                BDJones
                wrote on last edited by
                #7

                Thank you for the extra comments Pete, much appreciated. Guess I better take a look at resource dictionaries.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups