如何使用c#改进此代码

Som*_*ody 4 c# string

可能重复:
如果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)

Ste*_*art 7

while ((new char[] {' ', ',', '.'}).Contains(txtSource.Text[startPos]))
Run Code Online (Sandbox Code Playgroud)


sll*_*sll 5

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)