Why does the 'stackalloc' keyword not work with properties?

巧了我就是萌 提交于 2019-12-06 03:27:00

stackalloc must be part of the local variable declaration, as discussed in the documentation.

The [stackalloc] keyword is valid only in local variable initializers. The following code causes compiler errors.

int* block;
// The following assignment statement causes compiler errors. You
// can use stackalloc only when declaring and initializing a local 
// variable.
block = stackalloc int[100];

As such it truly is a syntax error; and rejects the obj.Property = stackalloc .. form.

(The later assignment to a property is an - uncaught - semantic error.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!