return 值为布尔值的方法
Method with return value as boolean
我有以下代码,其中 ShellExecuteEx return 执行时的布尔值 true 或 false。我通过将其转换为字符串将其分配给 class 级别变量。
strShellCallStatus = ShellExecuteEx(ref info).ToString();
[DllImport("shell32.dll", CharSet = CharSet.Auto)]
static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo);
public static void exev()
{
SHELLEXECUTEINFO info = new SHELLEXECUTEINFO();
info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info);
info.lpVerb = "open";
info.lpFile = "c:\windows\notepad.exe";
info.nShow = 5;
info.fMask = 0x440;
info.hwnd = IntPtr.Zero;
strShellCallStatus = ShellExecuteEx(ref info).ToString();
}
我应该关注 ShellExecuteEx return空值吗?如果是这样,我想使用以下语句:
strShellCallStatus = Convert.ToString(ShellExecuteEx(ref info));
只要 ShellExecuteEx
签名不是 bool? ShellExecuteEx()
,你就不应该害怕它 return null
因为 bool
是一个值键入默认 false
.
简单 - 签名为 bool ShellExecuteEx()
的方法不能 return null
因为它甚至无法编译。
我有以下代码,其中 ShellExecuteEx return 执行时的布尔值 true 或 false。我通过将其转换为字符串将其分配给 class 级别变量。
strShellCallStatus = ShellExecuteEx(ref info).ToString();
[DllImport("shell32.dll", CharSet = CharSet.Auto)]
static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo);
public static void exev()
{
SHELLEXECUTEINFO info = new SHELLEXECUTEINFO();
info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info);
info.lpVerb = "open";
info.lpFile = "c:\windows\notepad.exe";
info.nShow = 5;
info.fMask = 0x440;
info.hwnd = IntPtr.Zero;
strShellCallStatus = ShellExecuteEx(ref info).ToString();
}
我应该关注 ShellExecuteEx return空值吗?如果是这样,我想使用以下语句:
strShellCallStatus = Convert.ToString(ShellExecuteEx(ref info));
只要 ShellExecuteEx
签名不是 bool? ShellExecuteEx()
,你就不应该害怕它 return null
因为 bool
是一个值键入默认 false
.
简单 - 签名为 bool ShellExecuteEx()
的方法不能 return null
因为它甚至无法编译。