0

LINQ で「AND」と「OR」をどのように書き出すのですか。「AND」キーワードと「&&」および「,」を試しました。

私もそれをグーグルで検索しましたが、役立つものは何も見つかりませんでした。

どんな助けでも大歓迎ですありがとう

編集:

    int[] moreScores = new int[]{12,12,45,45,87,96};
int[] scores = new int[] { 97, 92, 81, 60 };
        // Define the query expression.
        IEnumerable<int> scoreQuery =
            from score in scores
    and moreScores
            where score > 80
            select score;
4

6 に答える 6

2

使用する言語によって異なります

C#&&の場合、ANDおよびOR場合||、 VB場合、ANDおよびORの場合
ANDOR

今、あなたは何語を使っていますか?

更新 1

最初に 2 つのテーブルを結合しますか?

UNIONメソッドは、重複を戻りセットから除外します。

IEnumerable<int> scoreQuery =  from score in (scores.Union(moreScores))
                               where score > 80
                               select score;

ここに画像の説明を入力

于 2012-07-30T10:27:21.977 に答える
1

ANDを間に入れて、2つの異なる配列を単純にクエリすることはできません。次のコードを試してください。

var moreScores = new int[] { 12, 12, 45, 45, 87, 96 };
var scores = new int[] { 97, 92, 81, 60 };
var scoreQueryResults =
    from score in (scores.Union(moreScores))
    where score > 80
    select score;

また、Linqの一般的な例もあります。

var list = new List<string>();
// ... add some items

// Searching for the strings that starts with J AND ends K
// Method Chain Format
var results1 = list.Where(item => item.StartsWith("J") && item.EndsWith("K"));
// Query Format
var results2 = from item in list
                where item.StartsWith("J") && item.EndsWith("K")
                select item;

// Searching for the strings that starts with J OR K
// Method Chain Format
var results3 = list.Where(item => item.StartsWith("J") || item.StartsWith("K"));
// Query Format
var results4 = from item in list
                where item.StartsWith("J") || item.StartsWith("K")
                select item;
于 2012-07-30T10:33:03.263 に答える
1

あなたが望むのはConcatスコアでは一般的に何も除外したくないと思うからUnionです。

int[] moreScores = new int[] { 12, 12, 45, 45, 87, 96 };
int[] scores = new int[] { 97, 92, 81, 60 };

IEnumerable<int> scoreQuery = from score in moreScores.Concat(scores)
                              where score > 80
                              select score;
于 2012-07-30T10:49:04.513 に答える
1

このようなことを書こうとしていると思います...

int[] moreScores = new int[]{12,12,45,45,87,96}; 
int[] scores = new int[] { 97, 92, 81, 60 };         
// Define the query expression.         
IEnumerable<int> scoreQuery = from score in scores.Union(moreScores) 
                              where score > 80             
                              select score; 
于 2012-07-30T10:41:52.753 に答える