unreachable code

  • Thread starter Thread starter mp
  • Start date Start date
M

mp

I tried to use a ref parameter in a method
private string GetCommentFromLine(string Origline,ref string CleanedLine)
{
int pos = Origline.IndexOf(";", 1);

if (pos > 0)
{
MessageBox.Show("Has comment");
return Origline.Substring(pos);
CleanedLine=Origline.Substring(1,pos-1);
}
else
{MessageBox.Show("Has no comment");
return "";

}

}

i get the error
Warning 1 Unreachable code detected

at "CleanedLine" in the line:
CleanedLine=Origline.Substring(1,pos-1);

what am i doing wrong?
 
Peter Duniho said:
mp said:
[...]
if (pos > 0)
{
MessageBox.Show("Has comment");
return Origline.Substring(pos);
CleanedLine=Origline.Substring(1,pos-1);
}
[...]

i get the error
Warning 1 Unreachable code detected

at "CleanedLine" in the line:
CleanedLine=Origline.Substring(1,pos-1);

what am i doing wrong?

You're returning from the method before it can reach that line of code.

The issue has nothing to do with the parameter being a "ref" parameter.
It's just how you wrote the code in the method. And the compiler is
telling you _exactly_ what the problem is.

Pete

oh! duh! I see now...maybe i should clean my glasses :-)
I guess i'm crazy (you already knew that <g>) but I thought the error popped
up when i added the ref in front of the parameter...
thanks
mark
 
Back
Top