0

I am trying to create a string function, but when I start to implement code it's yelling at me at the first line of code.

I've tried to just implement public static string IsUniqueChar(string str), public string IsUniqueChar(string str), both of these throw an error. I know it's something small but I can't figure it out.

public static string IsUniqueChar(string str)
{
    for (int i = 0; i < str.Length; i++)
    {
        int val = str.ElementAt(i) - 'a';
    }
}

IsUniqueChar is underlined in red saying that "not all code paths return a value".

2
  • 3
    You need to return a string. Or change the function return type to void. Commented Oct 13, 2019 at 13:33
  • 3
    First of all, IsUniqueChar seems like a function that needs to return a bool, not a string. Second, regardless of the return type, you must make sure that the function returns an object/value of that type to get rid of this compiler error. Please note that methods that don't return anything should have a void return type. Commented Oct 13, 2019 at 13:34

1 Answer 1

2

You declare your method like a method returning a value of type string, but it doesn't return anything.. Try adding a return statement to it:

public static string IsUniqueChar(string str)
{
    for (int i = 0; i < str.Length; i++)
    {
        int val = str.ElementAt(i) - 'a';

    }
    return "hello";
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.