Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to search with the Contains method in a List if there are multiple columns of data?

Good afternoon, there is a List with several columns of data, here is an example

public static List<(double date, double profit)> data_good_proffit = 
  new List<(double date, double profit)>();

how to write to search using the Contains method in the Profit column?

data_good_proffit.Contains();

so writes an error

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Contain will do if you want to find out the entire tuple, e.g.

// Do we have date == 5.0 and profit == 7.1?
bool result = data_good_proffit.Contains((5.0, 7.1));

If you want to check for profit only and ignore the date try to query with a help of Linq:

using System.Linq;

...

// Do we have any item with profit == 7.1?
bool result = data_good_proffit.Any(item => item.profit == 7.1);

please, not that you have a list of tuples, with no separate columns existing.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading