统计以某个文本开头的字典项数

3

我有一个字典,看起来像这样

test1: 123
test2: 456
another1: abc
test3: 789
another2: def

如何在C#框架3.5中获取以“test”开头的所有项的计数?

1个回答

8

您可以在字典上使用LINQ扩展,以便执行以下操作:

int count = dict.Count(D=>D.Key.StartsWith("Test"));

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接