Bug: incorrect warning message, Unreachable expression code detected

  • Thread starter Thread starter Don Burden
  • Start date Start date
D

Don Burden

We've started converting some applications to the .NET 2.0 framework. When
compiling in VS 2005, I'm getting a warning on this line:
return (unitWidth != null ) ? unitWidth : new Unit("0px");

Looks valid to me, but this gives a warning with "new" underlined saying
"warning CS0429: Unreachable expression code detected".
 
Hi,

It looks valid indeed.

I just wrote this in a project:

string G( string q)
{
return (q != null) ? q : new string('r', 12);
}

and it did compiled without warning.
Can you post the complete method?
 
"Don Burden" <[email protected]> a écrit dans le message de (e-mail address removed)...

| We've started converting some applications to the .NET 2.0 framework.
When
| compiling in VS 2005, I'm getting a warning on this line:
| return (unitWidth != null ) ? unitWidth : new Unit("0px");
|
| Looks valid to me, but this gives a warning with "new" underlined saying
| "warning CS0429: Unreachable expression code detected".

My guess is that your code above this line will never allow unitWidth to be
null.

Joanna
 
Hi,

Not even that, I changed my method to :

string G( )
{
string q = "sfsdf";
return (q != null) ? q : new string('r', 12);
}

and I still do not get a warning


There must be another error somewhere
 
Back
Top