一个字符串,与几个不同的字符串比较字符串、几个、不同

2023-09-11 23:01:27 作者:风华笔墨、

我想给一个字符串许多字符串比较。如何在C#中做呢?

I want to compare one string with many strings. How is that done in C#?

推荐答案

如果你想检查一个字符串包含在一个字符串列表,你可以使用的 包含 扩展方法:

If you want to check if a string is contained in a list of strings you could use the Contains extension method:

bool isStringContainedInList = 
    new[] { "string1", "string2", "string3" }.Contains("some string")