String.ToLowerInvariant Method
Assembly: mscorlib (in mscorlib.dll)
If your application depends on the case of a string changing in a predictable way that is unaffected by the current culture, use the ToLowerInvariant method. The ToLowerInvariant method is equivalent to ToLower(CultureInfo.InvariantCulture).
Security Considerations
If you need the lowercase or uppercase version of an operating system identifier, such as a file name, named pipe, or registry key, use the ToLowerInvariant or ToUpperInvariant methods.
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.Although you should not use the Invariant string methods in a locale-sensitive situation, they do provide a small--but not insignificant--performance boost. The following code compares the ToLower and ToLowerInvariant methods, with the results showing a ~15% difference on my machine:
using System;
using System.Diagnostics;
namespace InvariantCultureTest
{
class Program
{
private const string _testA = "This is a short test string";
private const int _iterations = 1000000;
static void Main(string[] args)
{
TestToLower();
TestToLowerInvariant();
}
private static void TestToLower()
{
Stopwatch watch = Stopwatch.StartNew();
for (int i = 0; i < _iterations; i++)
{
_testA.ToLower();
}
watch.Stop();
OutputResults(watch, "ToLower()");
}
private static void TestToLowerInvariant()
{
Stopwatch watch = Stopwatch.StartNew();
for (int i = 0; i < _iterations; i++)
{
_testA.ToLowerInvariant();
}
watch.Stop();
OutputResults(watch, "ToLowerInvariant()");
}
private static void OutputResults(Stopwatch watch, string testName)
{
Console.WriteLine(
"{0}:{1} {2:0,0} iterations executed in {3}ms ({4:0,0} per second){1}",
testName,
Environment.NewLine,
_iterations,
watch.ElapsedMilliseconds,
(int)((double)_iterations / watch.Elapsed.TotalSeconds)
);
}
}
}
- 6/7/2007
- Anonymous1233457