Errore del compilatore CS0213

Aggiornamento: novembre 2007

Messaggio di errore

Impossibile utilizzare l'istruzione fixed per accettare l'indirizzo di un'espressione già di tipo fixed.
You cannot use the fixed statement to take the address of an already fixed expression

Una variabile locale in un metodo unsafe oppure un parametro è già fixed nello stack, pertanto non è possibile accettare l'indirizzo di una di queste due variabili in un'espressione fixed. Per ulteriori informazioni, vedere Codice unsafe e puntatori (Guida per programmatori C#).

Esempio

Il seguente codice di esempio genera l'errore CS0213:

// CS0213.cs
// compile with: /unsafe
public class MyClass
{
   unsafe public static void Main()
   {
      int i = 45;
      fixed (int *j = &i) { }  // CS0213
      // try the following line instead
      // int* j = &i;

      int[] a = new int[] {1,2,3};
      fixed (int *b = a)
      {
         fixed (int *c = b) { }  // CS0213
         // try the following line instead
         // int *c = b;
      }
   }
}