对C#构造函数extern修饰符目的 [英] Purpose of C# constructor extern modifier

查看:258
本文介绍了对C#构造函数extern修饰符目的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是C#构造函数extern修饰符的目的是什么?

我知道的extern方法的使用来调用Win32函数,但什么有关构造函数?

请给出实际的例子。

请注意这一点:

  MyClass类
{
    公共EXTERN MyClass的();
}
 

解决方案

我相信,一个外部的构造函数的一个用途/目的就是已经构造了CLR本身中实现。如果你拆开mscorlib.dll中使用反射,并期待在System.String类型,你会看到:

  [MethodImpl(MethodImplOptions.InternalCall)
公共EXTERN字符串(CHAR []值);
 

这基本上告诉我们(的char [])构造函数的字符串类是外部实现,的作为.NET运行库的一部分的。

What is the Purpose of C# constructor extern modifier?

I know about usage of extern METHODS to invoke Win32 functions, but what about CONSTRUCTORS?

Please give the practical example.

Note this:

class MyClass
{
    public extern MyClass();
}

解决方案

I believe one use/purpose of an extern ctor is to have the constructor implemented within the CLR itself. if you disassemble mscorlib.dll using Reflector and look at the System.String type, you'll see:

[MethodImpl(MethodImplOptions.InternalCall)]
public extern String(char[] value);

Which basically tells us that the (char[]) ctor for the string class is externally implemented, as part of the .net runtime.

这篇关于对C#构造函数extern修饰符目的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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