更新:2007 年 11 月
错误消息
stackalloc 不能用在 catch 或 finally 块中
stackalloc 关键字不可用在 catch 或 finally 块中。有关更多信息,请参见异常和异常处理(C# 编程指南)。
下面的示例生成 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()
{
}
}