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. Question on string.Format(...)

Question on string.Format(...)

Scheduled Pinned Locked Moved C#
tutorialquestion
5 Posts 2 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.
  • C Offline
    C Offline
    Charith Jayasundara
    wrote on last edited by
    #1

    Hi, Can you please give me a practical example to distingish below two methods.. Method 1 string.Format("something","Something"); Method 2 string.Format(CultureInfo.CurrentCulture,"something","Something"); Thanks!

    Charith Jayasundara

    C 1 Reply Last reply
    0
    • C Charith Jayasundara

      Hi, Can you please give me a practical example to distingish below two methods.. Method 1 string.Format("something","Something"); Method 2 string.Format(CultureInfo.CurrentCulture,"something","Something"); Thanks!

      Charith Jayasundara

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Your first example simply calls your second example but with null as the first parameter. The second example exlicitly uses the current culture to render the formatting. In other words, if you ask it to format a number it will place the delimiters and decimal markers in the correct place and with the correct characters. For example, if your culuture is set to EN-GB then 1.234 will be rendered, whereas if your culture is NL-NL the same number would be rendered as 1,234 The .NET documentation has extesive examples of how to use Format and on formatting in general, that should be your starting point.

      Developer Day Scotland 2 - Free community conference Recent blog posts: *Throwing Exceptions *Training Developers * Method hiding or overriding - or the difference between new and virtual

      C 1 Reply Last reply
      0
      • C Colin Angus Mackay

        Your first example simply calls your second example but with null as the first parameter. The second example exlicitly uses the current culture to render the formatting. In other words, if you ask it to format a number it will place the delimiters and decimal markers in the correct place and with the correct characters. For example, if your culuture is set to EN-GB then 1.234 will be rendered, whereas if your culture is NL-NL the same number would be rendered as 1,234 The .NET documentation has extesive examples of how to use Format and on formatting in general, that should be your starting point.

        Developer Day Scotland 2 - Free community conference Recent blog posts: *Throwing Exceptions *Training Developers * Method hiding or overriding - or the difference between new and virtual

        C Offline
        C Offline
        Charith Jayasundara
        wrote on last edited by
        #3

        Hi, Thank you for the reply. I understand how it works for numbers. But what is the purpose of setting the culture for normal strings?

        Charith Jayasundara

        C 1 Reply Last reply
        0
        • C Charith Jayasundara

          Hi, Thank you for the reply. I understand how it works for numbers. But what is the purpose of setting the culture for normal strings?

          Charith Jayasundara

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          Charith Jayasundara wrote:

          But what is the purpose of setting the culture for normal strings?

          Because some people like consistency and will set all parameters explicitly all the time. Other than that, I don't think it makes any difference for strings.

          Developer Day Scotland 2 - Free community conference Recent blog posts: *Throwing Exceptions *Training Developers * Method hiding or overriding - or the difference between new and virtual

          C 1 Reply Last reply
          0
          • C Colin Angus Mackay

            Charith Jayasundara wrote:

            But what is the purpose of setting the culture for normal strings?

            Because some people like consistency and will set all parameters explicitly all the time. Other than that, I don't think it makes any difference for strings.

            Developer Day Scotland 2 - Free community conference Recent blog posts: *Throwing Exceptions *Training Developers * Method hiding or overriding - or the difference between new and virtual

            C Offline
            C Offline
            Charith Jayasundara
            wrote on last edited by
            #5

            Great :) Thank you!

            Charith Jayasundara

            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