invariantculture

What is the right string comparison value to be used in a machine to machine communication scenario?

我们两清 提交于 2021-01-28 05:33:03
问题 Consider a scenario where you are implementing code meant to be used for machine to machine communication. The typical example for that is the code executed inside a web API action method. Suppose that you want to perform an exact match between strings; maybe you have a list of users and you wan to find one specific user provided the user name: List<User> users = .... const string username = "user-123"; var user = users.Find(u => string.Equals(username, u.UserName)); In such a scneario should

When should I use StringComparison.InvariantCulture instead of StringComparison.CurrentCulture to test string equality?

元气小坏坏 提交于 2020-05-29 06:55:09
问题 Based on my understanding (see my other question), in order to decide whether to test string equality by using ordinal or cultural rules, the semantic of the performed comparison must be taken into account. If the two compared strings must be considered as raw sequences of characters (in other words, two symbols) then an ordinal string comparison must be performed. This is the case for most string comparisons performed in server side code. Example: performing a user lookup by username. In

C# parsing to datetime regardless of culture info

£可爱£侵袭症+ 提交于 2019-12-12 03:52:52
问题 I have problem parsing some date string where language is not english. The sample date string is "8 avril 2016 vendredi" which is "8 april 2016 friday" in english. I have tried this but no luck. DateTime dateTime; DateTime.TryParse("8 avril 2016 vendredi", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime); In my case, date string can be in any language so I cannot specify the culture in parsing. I appreciate your help. Thanks. 回答1: Behold, the terrible any parser! CultureInfo

DateTime formats used in InvariantCulture

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-09 08:50:11
问题 I have to pre-validate in Javascript a string that will be a DateTime in c#. The DateTime parse uses InvariantCulture. Does anyone know the DateTime formats defined for InvariantCulture? 回答1: Compiling information from here: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings Short Date Pattern ("d"): MM/dd/yyyy Long Date Pattern ("D"): dddd, dd MMMM yyyy Full Date Short Time ("f"): dddd, dd MMMM yyyy HH:mm Full Date Long Time ("F"): dddd, dd MMMM

Locale invariant guarantee of boost::lexical_cast<>

雨燕双飞 提交于 2019-12-01 17:32:07
I'm using boost::lexical_cast<std::string>(double) for converting doubles to string, generating JSON serialized byte stream, that is (on remote side) parsed by .NET. I'm able to force the .NET to use InvariantCulture for parsing, thereby returning predictable result on every possible language. However, I was not able to find this guarantee in boost::lexical_cast documentation. I tried it a little bit, and it works the same way for different locales set. But, I cannot be sure only from few tests, am I missing something in the documentation, or this cannot be guaranted at all, and I have to use

Locale invariant guarantee of boost::lexical_cast<>

柔情痞子 提交于 2019-12-01 16:56:16
问题 I'm using boost::lexical_cast<std::string>(double) for converting doubles to string, generating JSON serialized byte stream, that is (on remote side) parsed by .NET. I'm able to force the .NET to use InvariantCulture for parsing, thereby returning predictable result on every possible language. However, I was not able to find this guarantee in boost::lexical_cast documentation. I tried it a little bit, and it works the same way for different locales set. But, I cannot be sure only from few

how to set default culture info for entire c# application

冷暖自知 提交于 2019-11-28 05:40:33
I want to set default culture info for that class or for entire application. For example in Turkey 3,2 = in english 3.2 so application uses my local but i want it to use as default System.Globalization.CultureInfo.InvariantCulture How can i set it to that as default for that specific class or for entire application Alexei Levenkov Not for entire application or particular class. CurrentUICulture and CurrentCulture are settable per thread as discussed here Is there a way of setting culture for a whole application? All current threads and new threads? . You can't change InvariantCulture at all.

how to set default culture info for entire c# application

喜你入骨 提交于 2019-11-27 05:35:26
问题 I want to set default culture info for that class or for entire application. For example in Turkey 3,2 = in english 3.2 so application uses my local but i want it to use as default System.Globalization.CultureInfo.InvariantCulture How can i set it to that as default for that specific class or for entire application 回答1: Not for entire application or particular class. CurrentUICulture and CurrentCulture are settable per thread as discussed here Is there a way of setting culture for a whole