谁能给我展示MethodImplOptions.ForwardRef的示例 [英] Can anyone show me an example of MethodImplOptions.ForwardRef

查看:91
本文介绍了谁能给我展示MethodImplOptions.ForwardRef的示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MSDN 上,它看起来很酷a>:

It looks cool on MSDN:

指定方法已声明,但其实现为 在其他地方提供.

Specifies that the method is declared, but its implementation is provided elsewhere.

所以我在控制台应用程序中尝试过:

So I tried it in a console application:

public class Program
{
    [MethodImplAttribute(MethodImplOptions.ForwardRef)]
    public static extern void Invoke();

    static void Main(string[] args)
    {
        Invoke();
        Console.Read();
    }
}

那我现在该怎么办?在哪里可以提供Program.Invoke的实现?

Then what should I do now? Where can I provide the implementation of Program.Invoke?

推荐答案

我的理解ForwardRef的行为与extern相同,旨在在您使用的语言缺乏直接支持(通过C#中的extern).因此,用法应该与 the extern修饰符,最值得注意的是使用[DllImport(...)].

My understanding is that ForwardRef acts in the same way as extern, and is intended for guiding the runtime when the language you are using lacks direct support (via extern in C#). As such, the usage should be very similar to the extern modifier, most notably using [DllImport(...)].

这篇关于谁能给我展示MethodImplOptions.ForwardRef的示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆