Purpose of C# constructor extern modifier

后端 未结 2 1251
遇见更好的自我
遇见更好的自我 2021-02-04 08:45

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 t

2条回答
  •  伪装坚强ぢ
    2021-02-04 09:37

    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.

提交回复
热议问题