我想比较IF中的两个值 [英] I want to Compare two Values in IF else

查看:99
本文介绍了我想比较IF中的两个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hy

我想检查当前用户名是否在该部门可用Department_Id



我如何申请else声明



  string  Username = User.Identity.Name;  //  当前用户名 
DataTable dt;
Employee_In_Department Depart_Class = new Employee_In_Department();
Depart_Class.Retrieve_Employee_In_Department_By_All( ref Connection_string, out dt);
列表( byte )arr = new 列表(字节)();
for int i = 0 ; i < dt.Rows.Count; i ++)
{
arr.Add(Convert.ToByte(dt.Rows [i ] [ Department_Id])); // 表格中的所有部门ID
}

if (Username == arr)
{

}

解决方案

您可以使用条件运算符,例如&&,||这个操作符有助于复杂的表达。



 if(age == 40&& name ==hitesh )


Hy
I want to check that the current Username is available in that department or not Department_Id

How i Apply that in if else statement

string Username = User.Identity.Name;   // Current Username
DataTable dt;
Employee_In_Department Depart_Class = new Employee_In_Department();
Depart_Class.Retrieve_Employee_In_Department_By_All(ref Connection_string, out dt);
List(byte) arr = new List(byte)();
for (int i = 0; i < dt.Rows.Count; i++)
{
   arr.Add(Convert.ToByte(dt.Rows[i]["Department_Id"])); // All Department Id in table
}

if (Username ==arr )
{

}

解决方案

You can use Conditional Operator like &&,|| and !.This operator are helpful in complex expression.

if(age == 40 && name == "hitesh")


这篇关于我想比较IF中的两个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆