更新时间:2023-11-05 08:40:10
如果要计数,只需 Count()
借助 Linq 即可;要测试字符串是否相等,请使用 String.Equals
:
If you want to count, just Count()
with a help of Linq; to test if strings are equal use String.Equals
:
System.Linq;
...
// do not do Trim() repeatedly
String testValue = myInput.Trim();
int count = myList
.Count(item => String.Equals(item.Trim(),
testValue,
StringComparison.OrdinalIgnoreCase));