ECMA-334 C# Language Specification

17.5.7: External methods

When a method declaration includes an extern modifier, the method is said to be an external method. External methods are implemented externally, typically using a language other than C#. Because an external method declaration provides no actual implementation, the method-body of an external method simply consists of a semicolon.

The mechanism by which linkage to an external method is achieved, is implementation-defined.

[Example: The following example demonstrates the use of the extern modifier in combination with a DllImport attribute that specifies the name of the external library in which the method is implemented:
using System.Text;  
using System.Security.Permissions;  
using System.Runtime.InteropServices;  
class Path  
{  
   [DllImport("kernel32", SetLastError=true)]  
   static extern bool CreateDirectory(string name, SecurityAttribute sa);  
   [DllImport("kernel32", SetLastError=true)]  
   static extern bool RemoveDirectory(string name);  
   [DllImport("kernel32", SetLastError=true)]  
   static extern int GetCurrentDirectory(int bufSize, StringBuilder buf);  
   [DllImport("kernel32", SetLastError=true)]  
   static extern bool SetCurrentDirectory(string name);  
}  
end example]