Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Homework5
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- string[] strings1 = { "1", "2", "1" };
- string[] strings2 = { "3", "2" };
- List<string> resultingList = new List<string>();
- resultingList.Add(strings1[0]);
- TryAddElement(strings1, resultingList);
- TryAddElement(strings2, resultingList);
- for (int i = 0; i < resultingList.Count; i++)
- Console.WriteLine(resultingList[i]);
- }
- private static void TryAddElement(string[] strings, List<string> resultingList)
- {
- for (int i = 0; i < strings.Length; i++)
- {
- bool alreadyExists = false;
- for (int j = 0; j < resultingList.Count; j++)
- {
- if (strings[i] == resultingList[j])
- alreadyExists = true;
- }
- if (alreadyExists == false)
- resultingList.Add(strings[i]);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment