See Impossible to use ref and out for first ("this") parameter in Extension methods? - you would need to use ref
or out
as an option for the parameter, but they're mutually-exclusive with the this
modifier.
I don't think you have a good idea - because the code foo = 0;
is succint and immediately obvious what it does - wrapping it in an extension method is pointless because it doesn't solve any problems, it adds complexity, and adds the potential for bugs (what if one user of Reset
needs to reset to 1
instead of 0
and blindly changes the definition of Reset
? It would break the rest of your code.
Don't use a language feature just because it's there - a good programmer knows when to not use a language feature.
If you really do want to add functionality like this, use something like T4 or make a template extension for Roslyn.