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

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -