Is there constexpr like functionality/syntax (that can be used at compile-time in functions in C++) available in C#?
in C++, I can have a function (e.g. Fibonacci) like below:
constexpr int Fibonacci(int n) {
switch (n) {
case 0: return 0;
case 1: return 1;
default:
return Fibonacci(n - 1) + Fibonacci(n - 2);
}
}
and I can check in the main to ensure the function is correct by doing something like:
int main()
{
static_assert(Fibonacci(5) == 7, "Bad Program");
}
That means I do not have to wait till run time to evaluate if the Fibonacci function will work. It is like a simple test at a compile-time. I am asking if I can do thing kind of thing in C#.
What I have tried:
I google for this. Found that someone in quora mentioned java is missing this.
https://www.quora.com/What-is-the-counterpart-to-the-C++-constexpr-clause-in-languages-like-Java-or-C[
^]