Question on string.Format(...)
-
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
-
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
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
-
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
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
-
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
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
-
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
Great :) Thank you!
Charith Jayasundara