c# - Linq query to obtain count from a List -
i trying construct linq query in c# following scenario.
"given particular token "to identify count of documents in exists"
private list<document> documents = new list<document>(); class document { string filename; public string filename { { return filename; } } dictionary<string, int> tokens; public dictionary<string, int> tokens { { return tokens; } } public document(string filename, dictionary<string, int> tokens) { this.filename = filename; this.tokens = tokens; } }
with knowledge came expression:
documents.where(d => d.tokens.keys.any(k => k == word)).count();
but not sure whether 100% correct. in need of expert advice on this.
to make use of o(1) lookup time of dictionary should use containskey
instead.
documents.count(d => d.tokens.containskey(word));
Comments
Post a Comment