0
1

More than 3 years have passed since last update.

C#/Linq で シーケンスの完全一致をチェックする

Posted at

2つのシーケンスの内容を比較して、それぞれの要素がもう片方に必ず存在することを確認する

using System.Collections.Generic;
using System.Linq;
public class Hello{
    public static void Main(){
        // Your code here!
        var l1 = new List<int>(){1,2};
        var l2 = new List<int>(){1,2};

        var result = l1.All(y => l2.Any(l => l == y)) && l2.All(y => l1.Any(l => l == y));
        System.Console.WriteLine(result);
    }
}

0
1
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1