I am new to C # (a C ++ programmer is mostly with Java as a strong second, and some others I use less often); I am using C # with Unity, but I have a question that seems to be related to C #, not Unity.
I made some progress towards programming in a functional style, i.e. instead
I would do something like this
// Again C++ int someFunction(int a) { const int inputSquared = a * a; const int inputSquaredHalved = inputSquared / 2; return inputSquaredHalved * 3; }
Now I would like to do it in C #, but I tried this
// C
But Mono complains, saying that maxGrowth is not assigned a "constant value" - so I assume that the C # const keyword is actually equivalent to the "constexpr" from C ++ 11?
If so, is there a way to do what I want in C #? Preferably without calling some container class (if the compiler can't do this efficiently?).
I assume that with what I read, C # is much closer to Java in general than C ++ in the language; immutable classes, not constant functions?
source share