I have a method which basically looks at a variable and if its bool IsSelected == true then it sets the value to false, if not sets it to true.
Currently I have it written like
if( A.IsSelected)
{
A.IsSelected = false;
}
else
{
A.IsSelected = true;
}
Is it possible to write this like
A.IsSelected = !A.IsSelected
Sorry that this is a bit of a trivial question i’m just trying to cut down the ammount of code in my class and I Cant build the software to test it right now.
I know doing if (!A.IsSelected) will invert the bool but I wasnt sure it would work in this way for setting the value. Thanks
Yes it is possible and done all the time.