Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Purpose of C# constructor extern modifier

Tags:

c#

.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();
}
like image 589
sfedorov1982 Avatar asked Mar 05 '10 09:03

sfedorov1982


1 Answers

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.

like image 150
Rob Avatar answered Oct 11 '22 21:10

Rob