Suppose I have this code:
int a = 1;
int b = 2;
string s = (a + b == 3 ? "3" : array[a + b]);
I would like to declare a "local" variable to store (a+b) so that I don't need to compute it twice. I imagine something like that:
int a = 1;
int b = 2;
string s = (c == 3 ? "3" : array[c]) where c = a + b;
//from now on, c doesn't exist anymore
I know where doesn't exist. I tried to use using var c = a + b but I don't think it's possible. Is there a way?