asp.net 判断数组是否存在某个值的方法_实用技巧

分享到:
方法一:

string str1 = "0,1,2,3,4,5,6 ";
string[] str = str1.Split( ', ');
bool hasFlag=false;
foreach (string a in str)
{
if (a == "7 ")
{
hasFlag=true;
break;
}
}
if(hasFlag)
{ //执行当前页 }
else
{ //跳转 }

方法二

string [] flag = adminuser.Flag.Split('/');
List<string> list = new List<string>(flag);
if (list.Contains("9"))
Response.Write("当前操作用户"+adminuser.UserName.ToString());
else
Response.Write("<script>alert('您无权限进行此项操作');location.href='admin_main.aspx'</script>");
昵    称:
验证码: