windows 帮助修复 C# 中的错误“引用或输出参数必须是可赋值的”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7307705/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Help fixing errors in C# "A ref or out argument must be an assignable"
提问by Neel
Here's a block of code I'm having errors with:
这是我遇到错误的代码块:
public static bool Flash(Form form)
{
return (Win2000OrLater && FlashWindowEx(ref Create_FLASHWINFO(form.Handle, 15, uint.MaxValue, 0))); //A ref or out argument must be an assignable variable
}
public static bool Flash(Form form, uint count)
{
return (Win2000OrLater && FlashWindowEx(ref Create_FLASHWINFO(form.Handle, 3, count, 0))); //A ref or out argument must be an assignable variable
}
private static extern bool FlashWindowEx(ref FLASHWINFO pwfi);
public static bool Start(Form form)
{
return (Win2000OrLater && FlashWindowEx(ref Create_FLASHWINFO(form.Handle, 3, uint.MaxValue, 0))); //A ref or out argument must be an assignable variable
}
public static bool Stop(Form form)
{
return (Win2000OrLater && FlashWindowEx(ref Create_FLASHWINFO(form.Handle, 0, uint.MaxValue, 0))); //A ref or out argument must be an assignable variable
}
private static bool Win2000OrLater
{
get
{
return (Environment.OSVersion.Version.Major >= 5);
}
}
The error message is:
错误信息是:
A ref or out argument must be an assignable
ref 或 out 参数必须是可赋值的
回答by Russ Clarke
Regarding your first errors, you need to introduct the FlashWindow as a variable so for example
关于您的第一个错误,您需要将 FlashWindow 作为变量引入,例如
This:
这个:
public static bool Flash(Form form)
{
return (Win2000OrLater && FlashWindowEx(ref Create_FLASHWINFO(form.Handle, 15, uint.MaxValue, 0))); //A ref or out argument must be an assignable variable
}
becomes:
变成:
public static bool Flash(Form form)
{
if (Win2000OrLater)
{
FLASHWINFO fi = Create_FLASHWINFO(form.Handle, 15, uint.MaxValue, 0);
return (FlashWindowEx(ref fi));
}
return false;
}
回答by David Heffernan
You need an assignable variable for a ref or out param.
您需要一个可分配变量用于 ref 或 out 参数。
FLASHWINFO fwi = Create_FLASHWINFO(form.Handle, 15, uint.MaxValue, 0);
FlashWindowEx(ref fwi);