Advertisement
TeT91

ДЗ: Объединение в одну коллекцию

May 23rd, 2024
875
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace CSLight
  5. {
  6.     internal class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string[] numbers = { "1", "2", "3", "3", "1", "1", "5" };
  11.             string[] numbers2 = { "6", "6", "3", "3", "1", "5", "5" };
  12.             List<string> reworkedList = new List<string>();
  13.  
  14.             TryAddValuesToList(reworkedList, numbers);
  15.             TryAddValuesToList(reworkedList, numbers2);
  16.  
  17.             foreach (string value in reworkedList)
  18.             {
  19.                 Console.Write(value);
  20.             }
  21.  
  22.             Console.ReadKey();
  23.         }
  24.  
  25.         private static void TryAddValuesToList(List<string> finalValues, string[] sourceValues)
  26.         {
  27.             for (int i = 0; i < sourceValues.Length; i++)
  28.             {
  29.                 bool isSameValuesFound = false;
  30.  
  31.                 for (int j = 0; j < finalValues.Count; j++)
  32.                 {
  33.                     if (sourceValues[i] == finalValues[j])
  34.                     {
  35.                         isSameValuesFound = true;
  36.                         break;
  37.                     }
  38.                 }
  39.  
  40.                 if (isSameValuesFound == false)
  41.                 {
  42.                     finalValues.Add(sourceValues[i]);
  43.                 }
  44.             }
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement