.net - Hjælp til at fastsætte fejl i C # 'Et ref eller ud argument skal være en overdragelig'

Indlæg af Hanne Mølgaard Plasc

Problem



Her er en blok kode jeg har fejl med:


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


Fejlmeddelelsen er:



  Et ref-out-out-argument skal være en overdragelig


Bedste reference


Hvad angår dine første fejl, skal du introducere FlashWindow som en variabel som f.eks


Dette:


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
}


bliver til:


public static bool Flash(Form form)
{
    if (Win2000OrLater)
    {
        FLASHWINFO fi = Create\_FLASHWINFO(form.Handle, 15, uint.MaxValue, 0);
        return (FlashWindowEx(ref fi));
    }
    return false;
}

Andre referencer 1


Du har brug for en tildelbar variabel for en ref eller out param.


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