Can someone please tell me why the code below is not working?
int prePos = 0;
int preNeg = 0;
int postPos = 0;
int postNeg = 0;
for (int i = 0; i < pin1.GetLength(0); i++)
{
preNeg++ ? pin1[i, 0] < 0 : prePos++; //not working
pin2[i, 0] < 0 ? postNeg++ : postPos++; //not working
}
So the condition is if pin1[i, 0] is smaller than zero, preNeg get incremented by one. Else prePos should be inceremeted. I can do this by normal if else but why this ternary is not working?
Because ternary operator returns a value that is assigned to a variable or property;
like
a will have 1
syntax of ternary operator is
Moreover ternary operator is used to assign value to a single variable. not to two variables.