CS0269-fordítási hiba

A "parameter" előjel nélküli paraméter használata

A fordító nem tudta ellenőrizni, hogy a kimenő paraméter hozzá lett-e rendelve egy értékhez a használat előtt; a hozzárendelt érték nem határozható meg. Az érték elérése előtt mindenképpen rendeljen értéket a paraméterekhez out a hívott metódusban. Ha az átadott változó értékét kell használnia, használjon inkább egy paramétert ref . További információ: Metódusparaméterek.

1. példa

Az alábbi minta a CS0269-et hozza létre:

// CS0269.cs  
class C  
{  
    public static void F(out int i)  
    // One way to resolve the error is to use a ref parameter instead  
    // of an out parameter.  
    //public static void F(ref int i)  
    {  
        // The following line causes a compiler error because no value  
        // has been assigned to i.  
        int k = i;  // CS0269  
        i = 1;  
        // The error does not occur if the order of the two previous
        // lines is reversed.  
    }  
  
    public static void Main()  
    {  
        int myInt = 1;  
        F(out myInt);  
        // If the declaration of method F is changed to require a ref  
        // parameter, ref must be specified in the call as well.  
        //F(ref myInt);  
    }  
}  

2. példa

Ez akkor is előfordulhat, ha egy változó inicializálása próbablokkban történik, amelyet a fordító nem tud ellenőrizni, sikeresen végrehajtja:

// CS0269b.cs  
class C  
{  
    public static void F(out int i)  
    {  
        try  
        {  
            // Assignment occurs, but compiler can't verify it  
            i = 1;  
        }  
        catch  
        {  
        }  
  
        int k = i;  // CS0269  
        i = 1;  
    }  
  
    public static void Main()  
    {  
        int myInt;  
        F(out myInt);  
    }  
}