我有一个包含这样字符串的列表:
List<String> data = new List<String>
{
"marine",
"blue",
"SEM",
"seven",
"sensible",
"six"
};
现在我想将此列表与字符串进行比较,并将匹配项添加到新列表中:
String input = "se";
List<String> newList = new List<String>;
匹配条件是,第一个字母应该相同(区分大小写)。在这种情况下,newList包含:
&#34; 7&#34;和&#34;明智的&#34;
性能最佳的解决方案是什么?
答案 0 :(得分:5)
var newList = data.Where(s => s.StartsWith(input)).ToList();