Boolean 和 bool 的区别?

来源:百度知道 编辑:UC知道 时间:2024/06/05 02:21:16
说明:ExecSQL用来执行SQL语句。
/// 返回值:操作是否成功(True\False)。
/// 参数:sQueryString SQL字符串
/// 创建日期:2006-1-22
/// 创建人:张耀庭
/// </summary>

public Boolean ExecSQL(string sQueryString)
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
con.Open();
SqlCommand dbCommand = new SqlCommand(sQueryString, con);
try
{
dbCommand.ExecuteNonQuery();
con.Close();
}
catch
{
con.Close();
return false;
}
return true;
}

//把boolean改成bool行吗?为什么

bool 是C# 类型

System.Boolean是 .NET Framework 类型

前者(bool)是后者的别名。这和string及String的关系是一样的。
可以交替使用,使用上没任何区别。
在VS2015中,如果你使用Boolean去声明一个变量或方法,自带的智能提示会提示你是否需要简化为bool。也就是说,VS更加推荐你使用bool这个关键字。