Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn this if-then logic into a boolean expression?

I'm having a bit of a brain fart on making this code more concise(preferably a single boolean expression)

This is my code:

                    if (d.Unemployed)
                    {
                        if (type.Unemployed)
                        {
                            tmp.Unemployed = true;
                        }
                        else
                        {
                            tmp.Unemployed = false;
                        }
                    }
                    else
                    {
                        if (type.Unemployed)
                        {
                            tmp.Unemployed = false;
                        }
                        else
                        {
                            tmp.Unemployed = true;
                        }
                    }

Basically the point is that if either type or d is not unemployed, then tmp should be set to not unemployed.

like image 415
Earlz Avatar asked Nov 30 '22 04:11

Earlz


1 Answers

How about:

tmp.Unemployed = type.Unemployed == d.Unemployed;
like image 107
MRAB Avatar answered Dec 04 '22 22:12

MRAB