In C# 7.2, ref extension methods are allowed. This was not allowed in prior versions. You would have to declare the method like this:
public static void AddTo(this ref int inInt, int inAmountToAdd)
{
inInt += inAmountToAdd;
}
And then also use VS 2017 (requires version 15.5 or newer) with the language version set to 7.2 (or latest).
Note that when you use this feature, the caller must call the method with something that can act as ref in the receiver position (i.e. a field, local variable, or array slot). If you were planning on using this in some kind fluent API, it might not work as expected. For example, this would fail to compile: GetInt().AddTo(1)
because the return value of the method GetInt is not a valid ref
.
Note the above syntax might require 15.6 as per this issue but the feature should be available in 15.5 using ref this
if I am reading this correctly.