PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, August 12, 2022

[FIXED] how to check for a value in a list of decimal C#

 August 12, 2022     .net, c#, c#-4.0, compare, decimal     No comments   

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:

List.Find(Predicate) Method

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing