Does adding to a method group count as using a variable?
Posted
by
Vaccano
on Stack Overflow
See other posts from Stack Overflow
or by Vaccano
Published on 2011-02-14T22:43:28Z
Indexed on
2011/02/14
23:25 UTC
Read the original article
Hit count: 265
I have the following code example taken from the code of a Form
:
protected void SomeMethod()
{
SomeOtherMethod(this.OnPaint);
}
private void SomeOtherMethod(Action<PaintEventArgs> onPaint)
{
onPaint += MyPaint;
}
protected void MyPaint(PaintEventArgs e)
{
// paint some stuff
}
The second method (SomeOtherMethod
) has resharper complaining at me. It says of onPaint
that "Value assigned is not used in any execution path".
To my mind it was used because I added a method to the list of methods called when a paint was done.
But usually when resharper tells me something like this it is because I am not understanding some part of C#. Like maybe when the param goes out of goes out of scope the item I added to the list gets removed (or something like that).
I thought I would ask here to see if any one knows what resharper is trying to tell me.
(Side Note: I usually just override OnPaint. But I am trying to get OnPaint to call a method in another class. I don't want to expose that method publicly so I thought I would pass in the OnPaint group and add to it.)
© Stack Overflow or respective owner