Home > Back-end >  How can I assign List Values to a string?
How can I assign List Values to a string?

Time:10-13

If I have a string result="Out of Service" .And I want to update it to its short form if it matches with full name by comparing with a list that has values like attached image :

here

How can I do that?

CodePudding user response:

Using Linq

var result = "Out of Service";
result = shortForms.FirstOrDefault(model => model.Name == result)?.ShortName ?? result;
  • Related