ToUpperInvariant使用不依赖于区域性进行转换,而ToUpper则使用了当前线程的CultureInfo,进行转换,所以性能会有所影响,以下为测试:

         [Test]
public void TestInvariant()
{
Int32 count = * ;
Stopwatch watch = new Stopwatch(); String str = "abcdefghijklmnopqrstuvwxyz中华人民共和国";
watch = Stopwatch.StartNew();
for (int i = ; i < count; i++)
{
str.ToUpperInvariant();
}
Console.WriteLine("ToUpperInvariant:{0}", watch.Elapsed.ToString());
} [Test]
public void TestNoInvariant()
{
Int32 count = * ;
Stopwatch watch = new Stopwatch(); String str = "abcdefghijklmnopqrstuvwxyz中华人民共和国";
watch = Stopwatch.StartNew();
for (int i = ; i < count; i++)
{
str.ToUpper();
}
Console.WriteLine("ToUpper:{0}", watch.Elapsed.ToString());
}

ToUpperInvariant:00:00:00.2980660

ToUpper:00:00:00.3281423

如果 确认当前的比较和区域性无关的话,推荐使用ToUppperInvariant

使用ToUpperInvariant避免使用ToUpper的更多相关文章

  1. C函数tolower,与toupper

    tolower    将大写转换成小写.  非字母字符不做出处理.   这个函数用法有点特殊他是处理字符的,而不是处理字符串的. 所谓的不能处理字符串不是说他不能处理字符串,他处理的时候对字符串必须是 ...

  2. 尽量使用ToUpper比较,避免使用ToLower

    在编码时尽量使用ToUpper比较,避免使用ToLower,因为微软对ToUpper进行了优化,以下为测试结果: public void TestToLower() { Stopwatch watch ...

  3. toupper函数及一些小程序

    toupper 原型:extern int toupper(int c); 用法:#include <ctype.h> 功能:将字符c转换为大写英文字母 说明:如果c为小写英文字母,则返回 ...

  4. (stringstream toupper 空格) 词组缩写 hdu2564

    词组缩写 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  5. 字符串转换atof atoi atol gcvt strtod strtol strto ul toascii tolower toupper

    atof(将字符串转换成浮点型数) 相关函数 atoi,atol,strtod,strtol,strtoul 表头文件 #include <stdlib.h> 定义函数 double at ...

  6. linu 把文件中的字母小写转换为大写,大写转换为小写awk toupper tolower

    cat aa.txt|tr "[a-z]" "A-Z" [root@ob2 mytmp]# awk '{print toupper($0)}' aa2.txt ...

  7. R语言改变大小写 toupper()和 tolower()函数

    这些函数改变字符串的字符的大小写. 语法 toupper()和 tolower()函数的基本语法为: toupper(x) tolower(x) 以下是所使用的参数的说明: x - 向量输入. 示例 ...

  8. About toupper()

    // toupper.c #include <stdio.h> #include <string.h> #include <ctype.h> int main() ...

  9. ccf 201409-3 字符串匹配(toupper,tolower)

     ccf 201409-3 字符串匹配(toupper,tolower) 问题描述 给出一个字符串和多行文字,在这些文字中找到字符串出现的那些行.你的程序还需支持大小写敏感选项:当选项打开时,表示同一 ...

随机推荐

  1. 写在新建博客的第一天 分类: fool_tree的笔记本 2014-11-08 17:57 144人阅读 评论(0) 收藏

    来CSDN开博客的目的有两个: 其一是因为CSDN的代码输出,看过一些博文,觉得这里的代码输出真的很漂亮: 其二则是因为,感觉自己印象笔记用久了之后,渐渐地几乎不再自己写些东西了,习惯了方便的剪藏插件 ...

  2. UVA 10627 - Infinite Race(数论)

    UVA 10627 - Infinite Race option=com_onlinejudge&Itemid=8&page=show_problem&category=516 ...

  3. tcp ip参数详解

    http://www.cnblogs.com/digdeep/p/4869010.html 1. TCP/IP模型 我们一般知道OSI的网络参考模型是分为7层:“应表会传网数物”——应用层,表示层,会 ...

  4. Five ways to maximize Java NIO and NIO.2--reference

    Java NIO -- the New Input/Output API package-- was introduced with J2SE 1.4 in 2002. Java NIO's purp ...

  5. html、body、document、window的区别

    html是一门超文本标记语言: document对象代表整个html文档,可用来访问页面中的所有元素: body代表document的主体子对象,除浏览器头部,页面中能够看到的内容都属于body中的内 ...

  6. codevs 3119 高精度练习之大整数开根 (各种高精+压位)

    /* codevs 3119 高精度练习之大整数开根 (各种高精+压位) 二分答案 然后高精判重 打了一个多小时..... 最后还超时了...压位就好了 测试点#1.in 结果:AC 内存使用量: 2 ...

  7. 45种Javascript技巧大全

    JavaScript是一个绝冠全球的编程语言,可用于Web开发.移动应用开发(PhoneGap.Appcelerator).服务器端开发(Node.js和Wakanda)等等.JavaScript还是 ...

  8. Adb connect监听指定的主机和端口/Adb监听Visual Studio Emulator for Android模拟器

    语法: adb connect <host>[:<port>] 使用实例: adb connect //如果连接成功则返回 connected to 说明 在使用Visual ...

  9. C# 如何创建接口以及使用接口的简单Demo(转载!)

    //No:1  首先,我们要封装一个接口,接口中不要实现具体的方法(说白了这就是一个架子而已!) using System;using System.Collections.Generic;using ...

  10. ui线程和后台线程异步

    private void Button_Click(object sender, RoutedEventArgs e) { CreateElementOnSeperateThread(() => ...