@ABfBrsBtBBCCXWCY~| 64964VCCC 64696V~P5FF84WBCB-~C 647647VCB-~C 6477VCB~-~-

ToLower, ToUpper.` A cat has two states: sleeping and awake. In a similar way we have uppercase and lowercase letters. With ToLower and ToUpper we can convert cases.`Method notes.` ToLower changes strings to be all lowercase. It converts an entire string—without changing letters that are already lowercased or digits.`ToLower example.` We call ToLower on a string. It will return a copied version that is all lowercase. Characters such as digits will not be modified. Only uppercase letters are changed. `The first string is declared and the instance method ToLower is called on it. That method returns a new string that is lowercase.`Important: `The original string is not modified. The Console.WriteLine method is called with a format string.`Console.WriteLine `console`string.Format `format`Copy: `ToLower copies a string and returns a reference to the new string. The original string is unchanged.`Example, CultureInfo.` Next we use CultureInfo with ToLower. This example has improved performance over the code in the first example. This is shown in the benchmark later. `You can see that after the first string is declared, we declare a new CultureInfo, which we acquire from the CurrentCulture property.`Finally: `Internally this property fetches the current thread's globalization state. The program calls ToLower with one parameter.`Info: `Internally this method doesn't need to fetch the CurrentCulture because it already has it.`Performance.` Here I tested the performance of ToLower versus the performance of ToLowerInvariant. I found a difference between the two methods, with ToLower being faster. `CultureInfo: `I found that using an explicit CultureInfo was fastest. So we get an improvement by specifying CultureInfo.`Performance, notes.` When we access the CultureInfo of CurrentCulture, the code gets Thread.CurrentThread.CurrentCulture. This explains the speedup when CultureInfo is outside of the loop. `You can find more information about using globalizations when lowercasing strings by reading about the TextInfo class.`TextInfo `textinfo`Tip 2: `If a string is already lowercase, we can simply do nothing. We must first scan for validity.`IsUpper, IsLower `string-isupper-islower`ToUpper example.` ToUpper uppercases all letters in a string. It is useful for processing text input or for when you need to check the string against an already uppercase string. `Example: `ToUpper is an instance method on the string type, which means you must have a string variable instance to call it.`ToUpper works the same as ToLower except it changes lowercase characters to uppercase characters.`Notes, ToUpper.` In the program the CultureInfo.Invariant culture class specifies that you want the string to be uppercased the same way on all computers that might run your program. `If you need to uppercase the first letter, consider ToCharArray and char.ToUpper, not the ToUpper string instance method.`Uppercase First Letter `uppercase-first-letter`ToLowerInvariant.` ToLowerInvariant and ToUpperInvariant affect strings differently than ToLower and ToUpper. The word "invariant" indicates the system's culture has no effect on the result. `Example: `This program shows that the invariant methods act upon the characters in the expected way.`In some cases, these invariant methods can be different from other methods because they specify the invariant culture.`Notes, invariant.` Microsoft states that ToLowerInvariant and ToUpperInvariant are useful only for OS "identifiers" and only affect behavior with specific locales (Turkish). `These methods help when you need lowercase or uppercase version of an OS identifier, such as a file name, named pipe, or registry key.`ToLowerInvariant Method: Microsoft Docs `https://docs.microsoft.com/en-us/dotnet/api/system.string.tolowerinvariant`Char: `The char type offers a ToLowerInvariant method, which has the same effect for a char.`Notes, continued.` Invariant methods usually have the same effect as the default methods. In other words, ToLower is the same in most places to ToLowerInvariant. `Turkish: `The documents indicate that these methods will only change behavior with Turkish cultures.`A summary.` We used ToLower and ToUpper. We also used ToLowerInvariant—this was much slower than the ToLower method. For performance, we found an optimal ToLower call.

YZ^ ZPZOZSZDZ; { YZ$Y{^ YYZ{Input ZL. YY^ZL mixedCaseZz^"This is a MIXED ZVZL."^;^ YYZ{Call ToLower instance mZ[, which ZJs a Zwcopy. YY^ZL lowerZzmixedCase.^ToLower^();^ YYZ{Z5 ZIs. YY^Z%^"{0}, {1}"^,Z'mixedCase,Z'lower); Y} } ^ This is a MIXED ZVZL., this is a mixed ZVZL.^ ZPZO; ZPZO.GlobalizationZSZDZ; { YZ$Y{^ YYZ{Input ZL. YY^ZL upperZz^"UPPERCASE STRING"^;^ YYZ{Zqcurrent culture. YY^CultureInfo cultureZzCultureInfo.CurrentCulture;^ YYZ{Call ToLower instance mZ[ with globalization parameter. YY^ZL lowerZzupper.^ToLower^(culture);^ YYZ{Z5 ZI. YY^Z%lower); Y} } ^ upperZVZL^Input variables usedZkbenchmark: C#^ ZL textZz^"This is an UPPER ZL."^; CultureInfo cZzCultureInfo.CurrentCultureZS^Statements testedZkloops: C#^ ZL text2Zztext.ToLower()ZSZL text2Zztext.ToLowerInvariant()ZSZL text2Zztext.ToLower(c)ZS^Results: 10000000 iterations^ ToLower():YYY^1054 ms^ ToLowerInvariant(): ^1724 ms^ ToLower(CultureInfo): ^ 884 ms^ [fastest]^ ZPZO; ZPZO.GlobalizationZSZDZ; { YZ$Y{^ YY// YYZ{UpperZVthis mixed ZVZL. YY// YY^ZL Zd1Zz^"LowerZVZL."^; YYZL upper1ZzZd1.^ToUpper^(); YYZ%upper1);^ YY// YYZ{UpperZVthis ZL. YY// YY^ZL Zd2Zz^"ABC123"^; YYZL upper2ZzZd2.^ToUpper^(CultureInfo.InvariantCulture); YYZ%upper2); Y} } ^ LOWERCASE STRING. ABC123^ ZPZOZSZDZ; { YZ$Y{^ YYZ{This demonstrates the invariant mZ[s. YYZ2They actZkthe expected way. YY^ZL test1Zz^"Cat"^; YYZ%test1.^ToLowerInvariant^()); YYZ%test1.^ToUpperInvariant^()); Y} } ^ cat CAT^

WToLowerdSystem.GlobalizationWToUpperfinvariant case methods