"Value assigned is not used in any execution path"

I've seen a number of these messages where the value is used even in the same code block as the declaration. Looks like a bug to me.

2 comments

Please provide an example

--
Eugene Pasynkov
ReSharper Technical Lead
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


"suedeuno" <no_reply@jetbrains.com> wrote in message
news:14459075.83781226069811404.JavaMail.jive@app4.labs.intellij.net...

I've seen a number of these messages where the value is used even in the
same code block as the declaration. Looks like a bug to me.



0

Here's an example:

int x = 3;
someControl.Invoke(new MethodInvoker(() => { double y = Math.Cos(x); }));


//double z = Math.Cos(x); <-- if I uncomment this line, the "assigned value not used" goes away.

As it stands with the code above, the "= 3" is grayed out and if I hover over it it says "Value assigned is not used in any execution path".  Clearly the assigned value of 3 is being used, and if I remove the initialization (as Resharper is recommending), my code will be broken.

EDIT: Please note that I'm not suggesting the code I've provided is particularly useful or well-written.  My goal was to provide the simplest possible example of this that I've seen.

0

Please sign in to leave a comment.