string.ToLower() and string.ToLowerInvariant()

后端 未结 4 1743
孤独总比滥情好
孤独总比滥情好 2020-11-28 06:22

What\'s the difference and when to use what? What\'s the risk if I always use ToLower() and what\'s the risk if I always use ToLowerInvariant()?

4条回答
  •  时光取名叫无心
    2020-11-28 06:57

    I think this can be useful:

    http://msdn.microsoft.com/en-us/library/system.string.tolowerinvariant.aspx

    update

    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). The method is recommended when a collection of strings must appear in a predictable order in a user interface control.

    also

    ...ToLower is very similar in most places to ToLowerInvariant. The documents indicate that these methods will only change behavior with Turkish cultures. Also, on Windows systems, the file system is case-insensitive, which further limits its use...

    http://www.dotnetperls.com/tolowerinvariant-toupperinvariant

    hth

提交回复
热议问题