谁能给我展示MethodImplOptions.ForwardRef的示例 [英] Can anyone show me an example of MethodImplOptions.ForwardRef
问题描述
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屋!