Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq Where value is in Array

Tags:

IEnumerable<string> periods = new string[] {"ABC", "JKD", "223A"};  var someData = from p in returns                  from d in p.ReturnDet                  where p.Year > 2009                 where d.Period <is in periods array>  

How do I select values where the d.periods are contained in the periods array?

like image 817
thenth Avatar asked Sep 03 '10 15:09

thenth


People also ask

Can you use linq on an array?

LINQ is a Microsoft technology to perform operations on nearly all data sources. Here I have described nearly all data sources. Yes it supports General Arrays, Generic Lists, XML, Databases and even flat files.

Where with Contains in Linq?

LINQ Contains operator is used to check whether an element is available in sequence (collection) or not. Contains operator comes under Quantifier Operators category in LINQ Query Operators. Below is the syntax of Contains operator.

How do you find if an array contains a specific string in C#?

Contains() is a string method. This method is used to check whether the substring occurs within a given string or not. It returns the boolean value. If substring exists in string or value is the empty string (“”), then it returns True, otherwise returns False.


Video Answer


1 Answers

Use the Contains method.

var someData = from p in returns                   from d in p.ReturnDet                   where p.Year > 2009                  where periods.Contains(d.Period); 
like image 55
Adam Sills Avatar answered Oct 06 '22 14:10

Adam Sills