를 사용하는 방법은 다음과에서 는 Linq에와 IN 절
if (catid != 0)
posts = posts.Where(x => x.catid IN '1,8,2,109,23');
내 코드
입니다. 이 문제를 해결할 수있는 방법이 있습니까를 사용하는 방법은 다음과에서 는 Linq에와 IN 절
if (catid != 0)
posts = posts.Where(x => x.catid IN '1,8,2,109,23');
내 코드
입니다. 이 문제를 해결할 수있는 방법이 있습니까다른 목록을 사용해야 비교할 수도 있습니다.
List<int> cadIdFoundList = new List<int>();
cadIdFoundList.Add(1);
cadIdFoundList.Add(8);
// etc. . .
posts.Where(x => cadIdFoundList.Contains(x.catId));
int[] ids = new int[] { 1, 8, 2, 109, 23 };
var query = posts.Where(x => ids.Contains(x.catid));
롭 Conery 이전 discussed이 주제를 가지고있다.
심지어 더 간단 :
var query = posts.Where(x => new[] { 1, 8, 2, 109, 23 }.Contains(x.catid));
우리는 그곳에 새로운 []을 넣어야 만한다. 우리가 {1, 7, 3, 5} 할 수 있다면 멋지지 않겠습니까? 대신 포함 시키시겠습니까? :디 –
어쩌면 같은 뭔가 더 :
HashSet<int> categories = new HashSet<int>() { 1, 2, 8, 23, 109};
posts = posts.Where(post => categories.Contains(post.catid));
쿨. 고마워. 작동 해. – Luke101