文章内容

2016/12/9 17:11:00,作 者: 黄兵

C# 字符串转换为Bool类型

C# 字符串转换为Bool类型的方法:

1、判断等于某个值:

string  aKey="stringValue";
if(aKey== "stringValue1")
{ 
	MessageBox.Show(“转换成功!!!");
}
else
{
	MessageBox.Show("转换失败!!!");
} 

2、采用Convert.ToBoolean(String)

Convert.ToBoolean(String) 不是用来判断转换成bool是否成功的,它是用来将传入的值直接转换成bool类型.

注意:string类型的值为0,1,true,false 时。可以转换为bool类型。

分享到:

发表评论

评论列表