Count dictionary entries that start with specific text

I have a dictionary that looks something like this.

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

How can I get the number of all elements that start with a “test” in C # framework 3.5?

+3
source share
1 answer

You can use LINQ extensions in the dictionary so you can:

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

Source: https://habr.com/ru/post/1750514/


All Articles