Compilerfehler CS0255

Aktualisiert: November 2007

Fehlermeldung

"stackalloc" darf nicht in einem catch- oder finally-Block verwendet werden.
stackalloc may not be used in a catch or finally block

Das stackalloc-Schlüsselwort darf nicht in einem catch-Block oder einem finally-Block verwendet werden. Weitere Informationen finden Sie unter Ausnahmen und Ausnahmebehandlung (C#-Programmierhandbuch).

Im folgenden Beispiel wird CS0255 generiert:

// 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()
   {
   }
}