会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
JackYong
博客园
首页
新随笔
联系
订阅
管理
C#中判断空字符串的几种方法
Code
1
namespace
my
2
{
3
class
Program
4
{
5
static
void
Main(
string
[] args)
6
{
7
string
a
=
string
.Empty;
8
if
(a
==
""
)
//
执行效率(4)
9
{
10
Console.WriteLine(
@"
a==""
"
);
11
}
12
if
(a
==
string
.Empty)
//
执行效率(3)
13
{
14
Console.WriteLine(
"
a==string.Empty
"
);
15
}
16
if
(a.Length
==
0
)
//
执行效率最高(1)
17
{
18
Console.WriteLine(
"
a.Length == 0
"
);
19
}
20
if
(
string
.IsNullOrEmpty(a))
//
执行效率(2)
21
{
22
Console.WriteLine(
"
a==string.Empty
"
);
23
}
24
25
bool
b
=
IsNullOrEmpty(a);
26
Console.WriteLine(b);
27
28
}
29
30
/**/
///
<summary>
31
///
判断字符串是否为空
32
///
</summary>
33
///
<param name="value">
String 类型的值
</param>
34
///
<returns>
返回值 true ,false
</returns>
35
public
static
bool
IsNullOrEmpty(
string
value)
36
{
37
if
(value
!=
null
)
38
{
39
return
(value.Length
==
0
);
40
}
41
return
true
;
42
}
43
44
}
45
}
出处:
http://www.cnblogs.com/liuyong/
作者喜欢研究 Sql Server ,ASP.NET MVC , Jquery WCF 等技术,同时关心分布式架构的设计应用。转载请保留原文链接,谢谢!
posted @
2009-05-25 23:20
jackyong
阅读(
322
) 评论(
0
)
收藏
举报
刷新页面
返回顶部
公告