Victor Victor - 3 months ago 10
C# Question

Confusing use of a comma in an 'if' statement

I have this piece of code in C++:

ihi = y[0]>y[1] ? (inhi=1,0) : (inhi=0,1);


But how would it look in C#?

Answer

It means this:

if (y[0]>y[1])
{
    inhi = 1;
    ihi = 0;
} else {
    inhi = 0;
    ihi = 1;
}

Or written another way (in C++):

inhi = (y[0]>y[1]);
ini = !inhi;
Comments