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

I have a list of ids and I would like to build an if statement from each of those ids or if there is a better way?

I have one list that contains just ids

var listVal = new List<int>() { 1,2,3,4 };

another foreach

if (page.Id == 1 || page.Id == 2 || page.Id == 3 || page.Id == 4 )

Looking for a way to dynamically generate that if statement from the list listVal above or a better way to do this. Very new to C#

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

Not finding a way to do this.

>Solution :

if (listVal.Contains(page.Id)) {
    Console.Write("Ta-daa!");
}
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