Do you want to merge string arrays and yet want to keep the distinct values in C# ? . One of the option to do this is using the Union extension method.
Below is a sample code snippet demonstrating how to do it.
How to Merge string Arrays and keep distinct values using LINQ in C# ?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace GinktageConsoleApp
{
class Program
{
static void Main(string[] args)
{
MergeArray();
Console.ReadLine();
}
public static void MergeArray()
{
string[] movies1 = new string[] { "Kaththi", "Yennai Arindhaal", "Lingaa" };
string[] movies2 = new string[] { "Kaththi", "Jilla", "Veeram" };
string[] result = movies1.Union(movies2).ToArray();
foreach (var item in result)
Console.WriteLine(item);
}
}
}