Given a list of n values in a list. I've written the below to iterate through the collection and compare each value against the other members.
I feel it is a bit 'hacky' though and there's probably a better way to do it.
Can anyone give any tips?
Console.WriteLine("Enter a series of numbers seperated by a hyphen (-): ");
var userInput = Console.ReadLine().Split('-');
var inputList = new List<int>();
if (userInput.Count() > 1)
{
foreach (var item in userInput)
{
inputList.Add(int.Parse(item));
}
}
else
{
Console.WriteLine("Exiting....");
return;
}
var count = 0;
foreach (var num in inputList)
{
for (int i = 0; i < inputList.Count; i++)
{
if (num == inputList[i])
{
count++;
}
if (count != inputList.Count())
{
break;
}
}
}