计算Dictionary中以特定文本开头的项目

Chr*_*way 3 c# dictionary count

我有一本看起来像这样的字典

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

如何计算c#framework 3.5中以"test"开头的所有项目?

Leo*_*rke 8

您可以在字典上使用LINQ扩展,以便您能够:

int count = dict.Count(D=>D.Key.StartsWith("Test"));
Run Code Online (Sandbox Code Playgroud)