Answers for "get value from list c#"

C#
1

c# find element by condition

int[] plantHeights = { 3, 6, 4, 1, 6, 8 };

// Find the first occurence of a plant height that is greater
// than 5 inches
int firstHeight = Array.Find(plantHeights, height => height>5);
Posted by: Guest on March-04-2020
3

find a value in list of objects in c#

var item = TextPool.FirstOrDefault(o => o.Name == "test");
if (item != null)
       item.value = "Value";
Posted by: Guest on April-03-2020
0

c# get a value from value tuple list

// Using this extension method you can get the value you wish
static string GetAttributeValue(this IEnumerable<(string key, string value)> attributes, string attribute) =>
    attributes.Where(x => x.key == attribute).First().value;

// Obviously this does not work if you have multiple values that are the same
// So, NOTE that this assumes that you want to get the first occurance

// Usage:
List<(string, string)> values = new List<(string, string)>()
{ ("asd", "asd"), ("asd1", "asd1") };

string asdValue = values.GetAttributeValue("asd1");
// Output: asd1
Posted by: Guest on September-07-2021

Code answers related to "get value from list c#"

C# Answers by Framework

Browse Popular Code Answers by Language