I'm following a beginner C# guide that is teaching how to use public methods. I understand very little about how to properly use methods/functions, so sorry in advance if this question is obvious. I researched a bunch of questions asking the same thing, but wasn't able to find an answer for this situation.
The program is supposed to take the string text, send it to the CheckDuplicate function, and determine if it contains more than one of the same number. If so it should return string result with the value "Duplicate" or "No Duplicate", and then display it on the console.
Right now references to string return under the CheckDuplicate function have the error "variable assigned but its value is never used" and the program doesn't return "Duplicate" or "No Duplicate" when inputting a string.
class Program
{
public static string result;
static void Main(string[] args)
{
Console.WriteLine("Enter several numbers separated by -");
string text = Console.ReadLine();
if (String.IsNullOrEmpty(text))
{
Console.WriteLine("Empty");
}
else
{
result = CheckDuplicate(text);
}
Console.WriteLine(result);
}
public static string CheckDuplicate(string text)
{
var textArray = text.Split('-');
int[] textArrayNum = textArray.Select(s => int.Parse(s)).ToArray();
if (textArrayNum.Length != textArrayNum.Distinct().Count())
{
string result = "Duplicate";
}
else
{
string result = "No Duplicate";
}
return result;
}
}