I'm C/C++ to C# developer.
I need to do something like below,
#define LEN 20 int data[LEN]; Since C# doesn't support #define, many forums suggests to declare a const variable. A const variable might help me for below, but not for above.
for (int a = 0; a < LEN; a++) { x += data[LEN - a - 1]; } So, how do I use the constant for array declarations as well?
int x = data[LEN];doesn't declare an array-type variable, nor does it create an array - that has nothing to do with constants, it's just incorrect syntax. You could useint[] data = new int[LEN];...new[LEN]in C++. There are no arrays with automatic storage duration, as there is in C++. 2)#definedoesn't create a constant. It is merely a textual replacement, which uses find-and-replace to replace every occurence ofLENto20.int x = data[LEN];is corrected now.