Compiler Error CS0255
stackalloc may not be used in a catch or finally block
You cannot use the stackalloc operator in a catch or finally block. For more information, see Exceptions and Exception Handling.
The following sample generates CS0255:
C#
// 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()
{
}
}
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET feedback
.NET is an open source project. Select a link to provide feedback: