Partager via


Erreur du compilateur CS0255

Mise à jour : novembre 2007

Message d'erreur

stackalloc ne peut être utilisé dans un bloc catch ou finally
stackalloc may not be used in a catch or finally block

Le mot clé stackalloc ne peut pas être utilisé dans un bloc catch ou finally. Pour plus d'informations, consultez Exceptions et gestion des exceptions (Guide de programmation C#).

L'exemple suivant génère l'erreur CS0255 :

// CS0255.cs
// compile with: /unsafe
using System;

public class TestTryFinally
{
   public static unsafe void Test()
   {
      int i = 123;
      string s = "Some string";
      object o = s;

      try
      {
         // Conversion is not valid; o contains a string not an int
         i = (int) o;
      }

      finally
      {
         Console.Write("i = {0}", i);
         int* fib = stackalloc int[100];   // CS0255
      }
   }

   public static void Main()
   {
   }
}