Compare two list elements with LINQ

后端 未结 5 1561
一生所求
一生所求 2021-01-13 07:42

I\'m trying to find a LINQ expression to compare two list elements.

What i want to do is:

List _int = new List { 1, 2, 3, 3, 4,         


        
5条回答
  •  抹茶落季
    2021-01-13 08:25

    List _int = new List { 1, 2, 3, 3, 4, 5 };
    Enumerable.Range(0, _int.Count - 1)
        .Select(i => new {val = _int[i], val2 = _int[i + 1]})
        .Where(check => check.val == check.val2)
        .Select(check => check.val);
    

提交回复
热议问题