CS0133 “The expression being assigned to 'identifier' must be constant” - what's the reason behind that?

前端 未结 4 1256
感情败类
感情败类 2020-12-03 16:47

With a lot of C++ background I\'ve got used to writing the following:

const int count = ...; //some non-trivial stuff here
for( int i = 0; i < count; i++          


        
4条回答
  •  时光说笑
    2020-12-03 17:50

    You can't assign a variable number to a const. It is a compile time constant.

    From the C# reference on const:

    A constant expression is an expression that can be fully evaluated at compile time.

提交回复
热议问题