我的问题是我想检查一个字符串是否包含我设置的三个字符数组中的一个或多个,并且在大多数情况下我让它工作但由于一些奇怪的原因一行不想工作而我不想'不知道我做错了什么。
这三个数组是
a = af 小写字母
b = AF 大写字母
c = 1-6 个数字
该程序适用于:小写,大写,数字,小写+数字,大写+数字和小写+大写+数字,但不起作用的是小写+大写(c.Any(x.Contains) == false && a.Any(x.Contains) == true && b.Any(x.Contains) == true)
代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
Char[] a = { 'a', 'b', 'c', 'd', 'e', 'f' };
Char[] b = { 'A', 'B', 'C', 'D', 'E', 'F' };
Char[] c = { '1', '2', '3', '4', '5', '6' };
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = "";
if(textBox2.Text != "")
{
Char[] x = textBox2.Text.ToCharArray();
if (c.Any(x.Contains) == true && a.Any(x.Contains) ==false && b.Any(x.Contains)==false)
{
textBox1.Text = "num";
}
else if (b.Any(x.Contains) == true && c.Any(x.Contains) == false && a.Any(x.Contains) ==false)
{
textBox1.Text = "cap";
}
else if (a.Any(x.Contains) == true && c.Any(x.Contains) == false && c.Any(x.Contains) == false)
{
textBox1.Text = "low";
}
else if (c.Any(x.Contains) == false && a.Any(x.Contains) == true && b.Any(x.Contains) == true)
{
textBox1.Text = "low&cap";
}
else if (a.Any(x.Contains) == true && c.Any(x.Contains) == true && b.Any(x.Contains) == false)
{
textBox1.Text = "low&num";
}
else if (b.Any(x.Contains) == true && c.Any(x.Contains) == true && a.Any(x.Contains) == false)
{
textBox1.Text = "cap&num";
}
else if (a.Any(x.Contains) == true && b.Any(x.Contains) == true && c.Any(x.Contains) == true)
{
textBox1.Text = "cap&num&low";
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
谢谢转发
编辑
没关系,我只是想通了该程序首先找到了仅小写的选项,并没有费心去进一步寻找...