Our Blog

Consider the following timestamp: 1995-07-14T13:05:00.0000000-03:00.

When asked what the -03:00 at the end is called, many developers answer, “a time zone.”

Well…

The -03:00 does represent the offset from UTC.
To get the UTC time, invert the offset sign then add it to the time such as 13:05 + 3 = 16:05 in UTC.


Okay, following this ok now more details..

The mistake is in thinking that the offset is all there is to a time zone. Nope.  A time zone is a geographical area, and it consists of many pieces of information, such as

- One or more offsets. (DST is a thing, after all.)
- The dates when DST transitions happen. (These can and do change whenever governments feel like it.)
- The amount of time applied when transitions happened. (It’s not one hour everywhere.)
- The historical records of changes to the above rules.

In short, is is not possible to establish the time zone by the offset!

In .NET there are 6 ways to compare strings.  Really? Why is it so difficult?

Ordinal

Performs a simple byte comparison that is independent of language. This is most appropriate when comparing strings that are generated programmatically or when comparing case-sensitive resources such as passwords.

OrdinalIgnoreCase

Treats the characters in the strings to compare as if they were converted to uppercase using the conventions of the invariant culture, and then performs a simple byte comparison that is independent of language. This is most appropriate when comparing strings that are generated programmatically or when comparing case-insensitive resources such as paths and filenames.

InvariantCulture

Compares strings in a linguistically relevant manner, but it is not suitable for display in any particular culture. Its major application is to order strings in a way that will be identical across cultures.

InvariantCultureIgnoreCase

Compares strings in a linguistically relevant manner that ignores case, but it is not suitable for display in any particular culture. Its major application is to order strings in a way that will be identical across cultures.

CurrentCulture

Can be used when strings are linguistically relevant. For example, if strings are displayed to the user, or if strings are the result of user interaction, culture-sensitive string comparison should be used to order the string data.

CurrentCultureIgnoreCase

Can be used when strings are linguistically relevant but their case is not. For example, if strings are displayed to the user but case is unimportant, culture-sensitive, case-insensitive string comparison should be used to order the string data.

Tip: You should always specify explicitly the comparer as the default value is not consistent. For instance, string.IndexOf uses the current culture whereas string.Equals uses Ordinal.

i.e.

string.Equals("", "", StringComparison.Ordinal);
new [] { "" }.Contains("", StringComparer.Ordinal);
new Dictionary(StringComparer.Ordinal);

</string,>

Refer to blog for additional samples and Rosyln analyzer to help with coding within your IDE.

About Us

Web/Mobile Solutions

Our Contacts

Cincinnati, OH 45069