I have two lists in the Main method and pass them to another method where I want to find the unique values. I can find the unique values but I keep getting errors when I try to return both string arrays. Here is my code. I want to return names1 and names2 from UniqueNames
using System;
using System.Linq;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
string[] names1 = new string[] { "Ava", "Emma", "Olivia" };
string[] names2 = new string[] { "Olivia", "Sophia", "Emma" };
Console.WriteLine(string.Join(", ", Program.UniqueNames(names1, names2)));
}
public static string[] UniqueNames(string[] names1, string[] names2)
{
names1 = names1.Where(s => !names2.Contains(s)).ToArray();
names2 = names2.Where(s => !names1.Contains(s)).ToArray();
return (names1, names2);
}
}
}