Nithya R

Error 1: 'reversestring1.Class1.ProgrammingTest.ReverseString(string)': not all code paths return a value

y iam getting this error.please reply.thanks in advance.




Re: Visual C# General error in reversestring programme

Rashmi Gopinath

Hi,

This error is caused when all code paths don't have a return value. For eg: if you have an if-condition and code the return statement within it and don't have any return for the else-condition, you will get this error.

Make sure that you have a return statement for all your code paths.

Thanks,

Rashmi





Re: Visual C# General error in reversestring programme

bjreddy

public class ProgrammingTest

{

public string ReverseString(string word)

{

string inputString = "abcdefg";

string reversedString = string.Empty;

for (int c = inputString.Length; c > 0; c--)

{

reversedString += inputString[c - 1]

}

Console.WriteLine("Original String: " + inputString);

Console.WriteLine("Reversed String: " + reversedString);

}

}

hai Rashmi gopinath,this is my programme,now u tell me wr is the error.i am not using if condition.please reply.

thnaks.






Re: Visual C# General error in reversestring programme

M. Dirksma

You declared your method to return a string, which u arent doing.

This should do it:

Code Snippet

public class ProgrammingTest

{

public string ReverseString(string word)

{

string inputString = "abcdefg";

string reversedString = string.Empty;

for (int c = inputString.Length; c > 0; c--)

{

reversedString += inputString[c - 1]

}

Console.WriteLine("Original String: " + inputString);

Console.WriteLine("Reversed String: " + reversedString);

return reversedString;

}

}






Re: Visual C# General error in reversestring programme

Rashmi Gopinath

M. Dirksma is right. Your function needs to return the string. Just add "return reversedString;" as the last line of your code. Alternatively, if you dont want your function to return anything, you could declare it as "void".

Thanks,

Rashmi






Re: Visual C# General error in reversestring programme

bjreddy

Many thanks to M.Dirksma and Rashmi gopinath.