Bug: incorrect warning message, Unreachable expression code detected

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".
 
I

Ignacio Machin \( .NET/ C# MVP \)

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?
 
J

Joanna Carter [TeamB]

"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
 
I

Ignacio Machin \( .NET/ C# MVP \)

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top