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

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -