A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

C# program to demonstrate the example of Linq Intersect() method
Q:

C# program to demonstrate the example of Linq Intersect() method

0

C# program to demonstrate the example of Linq Intersect() method

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to demonstrate Linq Intersect() method, is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# Program to demonstrate Linq Intersect() method.

using System;
using System.Linq;
using System.Collections.Generic;

class Demo
{
    static void Main(string[] args)
    {
        List<int> List1 = new List<int>() { 10, 20, 30, 40, 50 };
        List<int> List2 = new List<int>() { 10, 40, 60, 80, 90 };

        var result = List1.Intersect(List2);

        foreach (var value in result)
        {
            Console.WriteLine(value + " ");
        } 
    }
}

Output:

10
40
Press any key to continue . . .

Explanation:

In the above program, we created two lists of integer numbers that are given below.

List<int> List1 = new List<int>() { 10, 20, 30, 40, 50 };
List<int> List2 = new List<int>() { 10, 40, 60, 80, 90 };

Here we used Linq Intersect() method to find common values of two lists using the below code.

var result = List1.Intersect(List2);

Then we print common values on the console screen using the below code.

foreach (var value in result)
{
    Console.WriteLine(value + " ");
} 

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now