Answers for "linq except"

C#
0

linq c# object except two lists

var filtered = unfilteredApps.Where(i => !excludedAppIds.Contains(i.Id));
Posted by: Guest on May-19-2020
0

linq dotnet Except

using System.Collections.Generic;
using System;
using System.Linq;
namespace LINQDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            List<Student> AllStudents = new List<Student>()
            {
                new Student {ID = 101, Name = "Preety" },
                new Student {ID = 102, Name = "Sambit" },
                new Student {ID = 103, Name = "Hina"},
                new Student {ID = 104, Name = "Anurag"},
                new Student {ID = 105, Name = "Pranaya"},
                new Student {ID = 106, Name = "Santosh"},
            };
            List<Student> Class6Students = new List<Student>()
            {
                new Student {ID = 102, Name = "Sambit" },
                new Student {ID = 104, Name = "Anurag"},
                new Student {ID = 105, Name = "Pranaya"},
            };
            
            //Method Syntax
            var MS = AllStudents.Except(Class6Students).ToList();
            //Query Syntax
            var QS = (from std in AllStudents
                      select std).Except(Class6Students).ToList();
            
            foreach (var student in MS)
            {
                Console.WriteLine($" ID : {student.ID} Name : {student.Name}");
            }
            
            Console.ReadKey();
        }
    }
}
Posted by: Guest on October-31-2021
0

c# except

using System;
using System.Linq;

class Program
{
    static void Main()
    {
        // Contains four values.
        int[] values1 = { 1, 2, 3, 4 };

        // Contains three values (1 and 2 also found in values1).
        int[] values2 = { 1, 2, 5 };

        // Remove all values2 from values1.
        var result = values1.Except(values2);

        // Show.
        foreach (var element in result)
        {
            Console.WriteLine(element);
        }
    }
}
/*
result
3
4
*/
Posted by: Guest on November-21-2020

C# Answers by Framework

Browse Popular Code Answers by Language