I have this array full of colors and have to find the one that only appears once in the array.
string[] colors = {"red","green","white","green","red","red"}
string[] noDupcolors = szinek.Distinct().ToArray(); //the same array without duplicates
int num = 0;
int once = 0;
for (int i = 0; i < noDupcolors.Length; i++)
{
for (int j = 0; j < S; j++)
{
if (noDupcolors[i]==colors[j])
{
num++;
}
if (num == 1)
{
once = j;
}
else
{
nums = 0;
}
}
}
Console.WriteLine(colors[once]);
I've tried this but for some reason it writes out green. Can someone help please. Thank you.