微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ValueType上的“ InstanceMethod”和“ StaticMethodref Type self”之间的区别?

如何解决ValueType上的“ InstanceMethod”和“ StaticMethodref Type self”之间的区别?

struct Vip
{
    internal int Id;
    internal int Age;
    internal int Weight;
    internal int Position;

    public void Move(int step)
    {
        Position += step;
    }

    public static void Move(ref Vip self,int step)
    {
        self.Position += step;
    }
    
    public static unsafe void MoveFast(ViP* self,int step)
    {
        self->Position += step;
    }
}

静态方法中的第一个参数扮演“ this”的角色。 我测试了这三种方法,发现实例方法比该方法显式包含“ this”的速度快。

在CLR下发生了什么事?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。