C#C
C#11mo ago
Faker

✅ Separate local function with explicit 'return' statement

C#

string[] words = {"racecar" ,"talented", "deified", "tent", "tenet"};

Console.WriteLine("Is it a palindrome?");
foreach (string word in words) 
{
    Console.WriteLine($"{word}: {IsPalindrome(word)}");
}

bool IsPalindrome(string word)
{
    int startPointerIndex = 0;
    int endPointerIndex = word.Length - 1;
    for (int i = 0; i < word.Length - 1; i++)
    {
        if (word[startPointerIndex] == word[endPointerIndex] && startPointerIndex < endPointerIndex)
        {
            continue;
        }
        else
        {
            return false;
        }

        startPointerIndex++;
        endPointerIndex--;
    }

    return true;
}

Hello guys, can someone explain why my IDE yells at me to use an "explicit" return statement pls. What is it trying to convey and why should I use it?
616DF90F-7850-49BA-A740-5F4B6423B9D6.png
Was this page helpful?