Extren is primarily used to declare methods that are implemented externally, and what is called an external implementation method, which is generally the introduction of an unmanaged code assembly using the DllImport method of the System.Runtime.InteropServices service. For example, the calling program Api,c the method of language writing, and so on. In this case, the declaration must be static
At the same time, the Extren keyword can also define an external assembly alias so that different versions of the same component can be referenced from a single assembly.
Here is a simple example of rewriting from MSDN, calling the system winmm. DLL Playback WAV file:
Declaration of the call to the system API
[System.Runtime.InteropServices.DllImport ("winmm.") DLL ", EntryPoint =" PlaySound ", SetLastError = True)]
public static extern void PlaySound (string path,system.intptr hmod,playsoundflags flags);
Call this method
string path = @ "C:22.wav";
Try
{
PlaySound (Path, new System.IntPtr (), playsoundflags.snd_sync);
}
catch (Exception ex)
{
Throw (ex);
}