Advertisement
Qrist

Common Elements

Apr 7th, 2020
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace GitHub
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string[] firstArr = new string[] { "Hey", "Hello", "2", "4" };
  11.             string[] secondArr = new string[] { "10", "Hello", "2", "8" };
  12.             string[] result = new string[secondArr.Length];
  13.             int length = Math.Min(firstArr.Length, secondArr.Length);
  14.             for (int i = 0; i < length; i++)
  15.             {
  16.                 if (firstArr.Contains(secondArr[i]))
  17.                 {
  18.                     result[i] = secondArr[i];
  19.                 }
  20.             }
  21.             Console.WriteLine(string.Join(" ", result));
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement