关于C#:搞砸const是个好主意吗?


Is it a good idea to mess up with consts?

如您所知,静态数组比动态数组快得多。 C允许您设置静态数组的大小,例如:

1
2
const unsigned int size = 5;
unsigned int data[size];

现在,我听说可以更改const的值了。

a)首先如何更改const的值?

b)如果我执行以下操作:

1
2
3
const unsigned int size = 5;
somehow change the value of size to 65
unsigned int data[size];

我输了什么?似乎太好了,难以置信?


有可能(请参见此答案),但结果将非常不编译器会在许多地方内联此常量,这就是为什么生成的代码会很快的原因。
因此,您将在某些地方看到size = 65,在其他地方看到size = 5