帮助修复C#中的错误“ref或out参数必须是可分配的”

时间:2011-09-05 11:55:45

标签: c# .net windows compiler-errors

以下是我遇到错误的代码块:

    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);
        }
    }

错误消息是:

  

ref或out参数必须是可赋值的

2 个答案:

答案 0 :(得分:1)

关于您的第一个错误,您需要将FlashWindow作为变量引入,例如

此:

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)
{
    if (Win2000OrLater)
    {
        FLASHWINFO fi = Create_FLASHWINFO(form.Handle, 15, uint.MaxValue, 0);
        return (FlashWindowEx(ref fi));
    }
    return false;
}

答案 1 :(得分:0)

你需要一个ref或out参数的可赋值变量。

FLASHWINFO fwi = Create_FLASHWINFO(form.Handle, 15, uint.MaxValue, 0);
FlashWindowEx(ref fwi);