LINQ way to count elements in each value of dictionary? -


i have dictionary<string, string[]> , i'm hoping linq way count strings in values. i'm using ol' fashioned for:

int total = 0; (int = 0; < dict.count; i++) {     total += dict.elementat(i).value.length; } 

i thinking of select() i'd have ienumerable<string[]> or 2d array of strings. there better way?

sum1 should work that

int total = dict.sum(d => d.value.length); 

here full working demo can test in linqpad or console app if inclined

dictionary<string, string[]> dict = new dictionary<string, string[]>(); for( int = 0; < 10; i++ ) {     dict["s"+i] = enumerable.range(0,10).select(s => s.tostring()).toarray(); } int total = dict.sum(d => d.value.length); console.write(total);//100 

1. msdn: enumerable.sum method


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -