Issue
how to check if a decimal value exists in a list of decimal C#.
I want to achieve the following, but I am looking for right way to compare a decimal value from a list of decimals.
decimal value = 100;
List<decimal > Amounts = new List<decimal>() { 20, 30 };
I want to compare if
Amounts.Any(value)
//do something
else
do something
Solution
You can use the .Find() method from here:
Example:
decimal valueToFind = 100;
List<decimal> amounts = new List<decimal>() { 20, 30 };
var result = amounts.Find(x => x == valueToFind);
if (result == 0){
//not found
}
else if (result == valueToFind){
//found
}
Answered By - troyw1636 Answer Checked By - Timothy Miller (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.