可能重复:
如果C#中的语句有更简单的方法吗
我有这个代码:
while ((txtSource.Text[startPos].ToString() == " ") ||
(txtSource.Text[startPos].ToString() == ",") ||
(txtSource.Text[startPos].ToString() == ".")))
{
// do something
}
Run Code Online (Sandbox Code Playgroud)
有没有办法像上面这样做:
while (!txtSource.Text[startPos].ToString() in (" ",",","."))
Run Code Online (Sandbox Code Playgroud)
while ((new char[] {' ', ',', '.'}).Contains(txtSource.Text[startPos]))
Run Code Online (Sandbox Code Playgroud)
LINQ Any()求助:
string text = "some text";
char[] controlChars = { ' ', ',', '.' };
int index = 1;
bool passed = controlChars.Any(c => c == text[index]);
Run Code Online (Sandbox Code Playgroud)