Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0255 

Error Message

stackalloc may not be used in a catch or finally block

The stackalloc keyword may not be used in a catch or finally block. For more information, see Exceptions and Exception Handling (C# Programming Guide).

The following sample generates 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;

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

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

   public static void Main()

Community Additions

© 2015 Microsoft