Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Demo
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> firstList = new List<int> { 3, 4, 5, 6 };
- List<int> secondsList = new List<int> { 1, 2, 4, 5, 7 };
- List<int> union = Union(firstList, secondsList);
- List<int> intersect = Intersect(firstList, secondsList);
- }
- public static List<int> Union( List<int> firstList, List<int> secondList)
- {
- List<int> union = new List<int>();
- union.AddRange(firstList);
- foreach (var item in secondList)
- {
- if (!union.Contains(item))
- {
- union.Add(item);
- }
- }
- return union;
- }
- public static List<int> Intersect(List<int> firstList, List<int> secondList)
- {
- List<int> intersect = new List<int>();
- foreach (var item in firstList)
- {
- if (secondList.Contains(item))
- {
- intersect.Add(item);
- }
- }
- return intersect;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment