c# - how to use ContainsKey with Linq and manage the case if key not found -


how convert code linq lambda expression?

var list = new list<string[]>(); foreach (var @char in _word) {      if (mapping.containskey(@char.tostring()))   // tried trygetvalue brain has thrown stackoverflow.           list.add(mapping[@char.tostring()]);      else            list.add(mapping["?"]); } 

if there no else part in previous code, linq expression following code don't know how also manage case key not found.

var list = _word.tochararray()                 .where(mot => mapping.containskey(mot.tostring()))                 .select(mot => mapping[mot.tostring()]); 

the solution must preserve order please.

var list = _word.select(mot => mapping.containskey(mot.tostring()) ? mapping[mot.tostring()] : mapping["?"]); 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -