【发布时间】:2019-01-14 21:21:48
【问题描述】:
出于某种原因,即使在 Visual Studio 中将其键入 C# 文件也足以导致它立即崩溃。为什么?
unsafe struct node {
node*[] child;
}
当 IDE 开始对关键字等进行着色时似乎会发生这种情况。
在 TIO 中尝试它会吐出 csc.exe exited with code 1 这不是很有帮助。
虽然 C# 中的数组声明与 C/C++ 中的不同,但上面的似乎应该是完全有效的。为什么不是,为什么它会导致 Visual Studio 崩溃?
我的 Visual Studio 版本是 14.0.23107。
【问题讨论】:
-
VS 2012 产生编译错误:
Cannot take the address of, get the size of, or declare a pointer to a managed type -
VS2017 瞬间,立即关闭
-
同上 LINQPad。 StackoverflowException。
-
我发现了一个存在的错误:github.com/dotnet/roslyn/issues/24978
-
FWIW 您的代码无效,因为您不能将指针指向包含 C# 中托管对象的结构。数组是托管对象。因此,即使 VS 没有崩溃,该代码也不会编译。
标签: c# visual-studio visual-studio-2015 roslyn