1. 首页
  2. 数据库
  3. 其它
  4. C# 判断字符为空的6种方法的效率实测对比

C# 判断字符为空的6种方法的效率实测对比

上传者: 2021-02-01 10:55:16上传 PDF文件 187.04KB 热度 10次
C#中提供了相当丰富的方法或属性来判断一个字符是否为空,常用的方法有以下6种 1. strTest== “” 2. strTest.Equals(“”) 3. strTest== string.Empty 4. strTest.Equals(string.Empty) 5. strTest.Length == 0 6. string.IsNullOrEmpty(strTest) 为了对以上6种方法的效率,有个直观的感受,我特意编写了以下的测试代码: using System; namespace StrTest { class Program { //定义3个字符串 以便测试
下载地址
用户评论