访问扩展方法的变量(C#)

dam*_*les 1 c# extension-methods

是否可以在静态扩展方法中修改this/focus变量?

例如:

public static class AnimExtensions
{
    public static int anim(this float f, float to, float time)
    {
        return Animation.Start(a => f = a, f, to, time);
    }
}
Run Code Online (Sandbox Code Playgroud)

我想通过在'this'变量上使用lambda函数来调用使用float的扩展的Animation.Start方法.扩展方法中不允许使用this关键字,但是有另一种方式以这种方式访问​​/使用变量吗?

Jon*_*eet 8

您当然可以修改参数 - 但它不会产生任何影响,因为参数按照常规方法按值传递.

您不能声明扩展方法的第一个参数,ref或者out它是生成效果所需的参数.