What do you mean by extern keyword in C# programming?

 Posted by Goud.Kv on 9/6/2014 | Category: C# Interview questions | Views: 524 | Points: 40
Answer:

extern is a c# keyword or modifier which calls an external method.
It is mostly used for interop services with DLLImport attribute. This will calls an external method from the particular dll library.
Example,
[DllImport("User32.dll", CharSet = CharSet.Unicode)]

public static extern int MessageBox(IntPtr i, string s1, string s2, int type);

static int Main()
{
string Name;
Console.WriteLine("Please type your message here: ");
Name = Console.ReadLine();
return MessageBox((IntPtr)0, Name, "Message Box", 0);
}


Asked In: Spotted While Learning | Alert Moderator 

Comments or Responses

Login to post response