我想知道,如何使用例如转义键终止程序.一般来说,我必须做什么来在application.run(..)之后停止它?
我怎么能插入这个
private void myForm_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e) {
if (e.KeyCode == Keys.Escape) {
Application.Exit();
}
}
Run Code Online (Sandbox Code Playgroud)
在下面的代码中
static void Main()
{
using (WinForm new_form = new WinForm())
{
new_form.InitializeComponent();
new_form.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
new_form.InitializeDevice();
new_form.LoadSurfaces();
new_form.Set3D();
Application.Run(new_form);
}
Run Code Online (Sandbox Code Playgroud)
}
我试图使用Reflection访问以下属性,因为我没有原始源代码(假设这是通过Reflector反编译的).它似乎是"私有虚拟"或者因为它在属性的开头有"_"的特殊之处.除了这个,我可以访问所有其他私有属性没问题.只是无法弄清楚我做错了什么:
private virtual String _MyProperty
{
get
{
return this.__MyProperty;
}
[MethodImpl(MethodImplOptions.Synchronized)] set
{
this.__MyProperty = "blah";
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用Reflection访问它,如下所示:
ReflectionHelper.GetPropertyValue(<class of above property>, "_MyProperty")
Run Code Online (Sandbox Code Playgroud)
在我的ReflectionHelper类中使用以下方法:
Public Shared Function GetPropertyValue(ByVal obj As Object, ByVal prop As String) As Object
Dim objectType As Type = obj.GetType()
Dim bindingFlags As BindingFlags = bindingFlags.GetProperty Or bindingFlags.Public Or bindingFlags.NonPublic Or bindingFlags.Instance
Dim propInfo As PropertyInfo = objectType.GetProperty(prop, bindingFlags)
If propInfo Is Nothing Then
Throw New Exception("Property: '" & prop & "' not found in: …Run Code Online (Sandbox Code Playgroud) 假设我在 SQL Server 2008 R2 中有一个名为 TABLE1 的表。我想从这个表中以编程方式获取 C# 或 VB.NET 中的列及其数据类型的列表。本质上类似于执行“sp_help TABLE1”。有小费吗?
我收到了一位供应商的消息,说明他们将删除对Interop库的支持,因为:
从.NET 4.0开始,不推荐使用托管代码和本机代码之间基于互操作的通信
它是否正确?如果是这样,那么正确的方法是什么?为什么?我无法理解为什么从Interop管理COM对象是个坏主意.就我记忆中的所有Office产品而言,微软都这样做.
当我们在调试会话期间调用/粘贴“GetAsyncKeyState(Keys.F4)”到 VS2013 的观察窗口时,它返回 204996608。我查看了 MSDN 文档,但我不知道如何理解这个数字。它想告诉我什么?
我必须错过.NET舍入的一些微妙之处.所以我看这个例子:
decimal num = 2.5M;
var result = Math.Round(num);
Run Code Online (Sandbox Code Playgroud)
为什么result = 2?(我本来应该预期3,因为它应该围绕)