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
Post a Comment