- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# program to find additional values in two lists
Firstly, set two lists in C#.
List One
List <string> list1 = new List <string> (); list1.Add("P"); list1.Add("Q"); list1.Add("R"); list1.Add("S"); list1.Add("T"); list1.Add("U"); list1.Add("V"); list1.Add("W");
List Two
List <string> list2 = new List <string> (); list2.Add("T"); list2.Add("U"); list2.Add("V"); list2.Add("W");
Now, to get the different values in both the lists, use the Except method. It returns the values in the first list which is not present in the second list.
Example
using System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main() { List <string> list1 = new List <string> (); list1.Add("P"); list1.Add("Q"); list1.Add("R"); list1.Add("S"); list1.Add("T"); list1.Add("U"); list1.Add("V"); list1.Add("W"); Console.WriteLine("First list..."); foreach(string value in list1) { Console.WriteLine(value); } Console.WriteLine("Second list..."); List <string> list2 = new List <string> (); list2.Add("T"); list2.Add("U"); list2.Add("V"); list2.Add("W"); foreach(string value in list2) { Console.WriteLine(value); } Console.WriteLine("Remaining values..."); IEnumerable <string> list3; list3 = list1.Except(list2); foreach(string value in list3) { Console.WriteLine(value); } } }
Output
First list... P Q R S T U V W Second list... T U V W Remaining values... P Q R S
- Related Articles
- Python program to find missing and additional values in two lists?
- Java program to find missing and additional values in two lists
- C# program to find common values from two or more Lists
- C# program to find Intersection of two lists
- Program to find median of two sorted lists in C++
- C# program to find Union of two or more Lists
- Python program to find Intersection of two lists?
- C# program to concat two or more Lists
- Python program to find Cartesian product of two lists
- Program to find minimum difference between two elements from two lists in Python
- Program to find union of two given linked lists in Python
- C# program to list the difference between two lists
- Python program to find Union of two or more Lists?
- Java Program to Join Two Lists
- Java Program to Merge two lists

Advertisements