Globalization and culture

T

Tony Johansson

Hi!

I just wonder these two rows 1 and 2 below give identical output for those
culture that I have tested with.
So my first question is if rows 1 and 2 are the same ?
My second question is how is it possible that these two rows give identical
output when I pass in two completely different object ?
In the first example I pass in a CultureInfo
In the second example you pass in a DateTimeFormatInfo

1. Console.WriteLine(DateTime.Now.ToString("D", new CultureInfo("sv-fi")));
2. Console.WriteLine(DateTime.Now.ToString("D", new
CultureInfo("sv-FI").DateTimeFormat));

//Tony
 
A

Alberto Poblacion

Tony Johansson said:
I just wonder these two rows 1 and 2 below give identical output for those
culture that I have tested with.
So my first question is if rows 1 and 2 are the same ?
My second question is how is it possible that these two rows give
identical output when I pass in two completely different object ?
In the first example I pass in a CultureInfo
In the second example you pass in a DateTimeFormatInfo

1. Console.WriteLine(DateTime.Now.ToString("D", new
CultureInfo("sv-fi")));
2. Console.WriteLine(DateTime.Now.ToString("D", new
CultureInfo("sv-FI").DateTimeFormat));

You are invoking an overload of the ToString method that takes an
IFormatProvider. Both CultureInfo and DateTimeFormatInfo implement that
interface. This interface declares a method called GetFormat(). If you are
seeing the same result from boths calls, it means that the developers of
both classes chose to implement the interface in such a way that the
GetFormat method is returning the same format in both cases.
 
T

Tony Johansson

Excellent explained !!

//Tony

Alberto Poblacion said:
You are invoking an overload of the ToString method that takes an
IFormatProvider. Both CultureInfo and DateTimeFormatInfo implement that
interface. This interface declares a method called GetFormat(). If you are
seeing the same result from boths calls, it means that the developers of
both classes chose to implement the interface in such a way that the
GetFormat method is returning the same format in both cases.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top