If we assume we have this little snippet of code:string str = checked;bool test1;if (str == checked){    test1 = true;}else{    test1 = false;}Is it bad practice to change a simple statement like this to the following?:bool test2 = (str == checked);Because they work exactly the same, and work as required, so I can't imagine how it would be. However, as a young, inexperienced programmer I am not aware of whether such a thing is frowned upon or not. Can anyone tell me, if this is NOT ok, why not?The following test program:using System;public class Test{    public static void Main()    {        string str = checked;        bool test1;        if (str == checked)        {            test1 = true;        }        else        {            test1 = false;        }        bool test2 = (str == checked);        bool test3 = (str != checked);        Console.WriteLine(test1.ToString());        Console.WriteLine(test2.ToString());        Console.WriteLine(test3.ToString());    }}Outputs:TrueTrueFalseAny insight etc is appreciated.
Making Simple IF Statements Shorter
programming practices;language agnostic;coding standards;conditions
Is it bad practice to change a simple statement like this to the following?:bool test2 = (str == checked);No, it's good practice. To me, the longer code:if (str == checked){      test1 = true;}else{    test1 = false;} indicates that the programmer doesn't understand Boolean expressions.  The shorter form is much clearer.  Similarly, don't write:if (boolean-expression) {    return true;} else {    return false;}Just write return boolean-expression;