设为首页 加入收藏

TOP

Interview questions for C# developers(二)
2014-11-24 01:37:50 来源: 作者: 【 】 浏览:23
Tags:Interview questions for developers
hich is the same as Monitor Enter/Exit:
lock(obj) { // code }


translates to


try {
CriticalSection.Enter(obj);
// code
}
finally
{
CriticalSection.Exit(obj);
}
How do you directly call a native function exported from a DLL – Here’s a quick example of the DllImport attribute in action:
using System.Runtime.InteropServices;
class C
{
[DllImport("user32.dll")]
public static extern int MessageBoxA(int h, string m, string c, int type);
public static int Main()
{
return MessageBoxA(0, “Hello World!”, “Caption”, 0);
}
}


This example shows the minimum requirements for declaring a C# method that is implemented in a native DLL. The method C.MessageBoxA() is declared with the static and external modifiers, and has the DllImport attribute, which tells the compiler that the implementation comes from the user32.dll, using the default name of MessageBoxA. For more information, look at the Platform Invoke tutorial in the documentation.
How do I simulate optional parameters to COM calls – You must use the Missing class and pass Missing.Value (in System.Reflection) for any values


首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C#面试题 下一篇新编C#面试题

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: