C#拆分字符串并在If语句中使用

Bat*_*uta 1 c# string if-statement

是否有更优雅的方式来实现这一目标.

我有一个字符串,我想在if语句中单独拆分和使用.例如:

string people = "John;Joe;Jane;Mike";
string[] names = people.Split(';');

if(person == "John" || person == "Joe" || person == "Jane" || person == "Mike")
{
    ....
}
else
{
    ....
}
Run Code Online (Sandbox Code Playgroud)

我猜这是一种更好的方法.

谢谢.

Lee*_*Lee 6

if(names.Contains(person)) { ... }
Run Code Online (Sandbox Code Playgroud)