Honey Singh
Honey Singh

Reputation: 7

How can I assign List Values to a string?

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?

Upvotes: 0

Views: 164

Answers (1)

Muhammad Sulaiman
Muhammad Sulaiman

Reputation: 2605

Using Linq

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

Upvotes: 1

Related Questions