
bool类型的方法在if语句中如何调用
我现在写了一个方法,代码如下:(c#)publicboolIsFriend(intfriendId){intnum=0;try{//创建SQL语句查询选中的好友是否已经是...
我现在写了一个方法,代码如下:(c#)
public bool IsFriend(int friendId)
{
int num = 0;
try
{
//创建SQL语句查询选中的好友是否已经是自己的好友
string sql = string.Format("select count(*) from friends where hostid={0} and friendid={1}", UserHelper.loginId, friendId);
//创建Command对象
SqlCommand cmd = new SqlCommand(sql, DBHelper.con);
//打开数据库连接
DBHelper.con.Open();
//执行SQL语句
num = (int)cmd.ExecuteScalar();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
DBHelper.con.Close();
}
if (num == 1)
{
return true;
}
else
{
return false;
}
}
我想把它用在if语句里,用来判断该friendId是否为我已经加了的好友号码。我该如何写?请高人指教~谢谢 展开
public bool IsFriend(int friendId)
{
int num = 0;
try
{
//创建SQL语句查询选中的好友是否已经是自己的好友
string sql = string.Format("select count(*) from friends where hostid={0} and friendid={1}", UserHelper.loginId, friendId);
//创建Command对象
SqlCommand cmd = new SqlCommand(sql, DBHelper.con);
//打开数据库连接
DBHelper.con.Open();
//执行SQL语句
num = (int)cmd.ExecuteScalar();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
DBHelper.con.Close();
}
if (num == 1)
{
return true;
}
else
{
return false;
}
}
我想把它用在if语句里,用来判断该friendId是否为我已经加了的好友号码。我该如何写?请高人指教~谢谢 展开
展开全部
//friendId根据需要设定的。
int friendId = 1;
if(IsFriend(friendId))
{
//我已经加了的好友号码
.....
}
else
{
//他不是我的好友
.....
}
int friendId = 1;
if(IsFriend(friendId))
{
//我已经加了的好友号码
.....
}
else
{
//他不是我的好友
.....
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
if (IsFriend(1)) {
//已经加了
}else{
//....................
}
//................................. < _ <
//已经加了
}else{
//....................
}
//................................. < _ <
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询