Reputation: 17
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".
Upvotes: 0
Views: 61
Reputation: 4943
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";
}
Upvotes: 2