I have the following code,
bool HasPassed= (result!= null && result.Identifier.Equals("Passed"))? true : false
This works fine as it is, but I was wondering if it were possible to write this code in a better and more simplified way, maybe using the ? operator ( or Null-coalescing operator). I'm still learning about this and did not quite understand how it can be used in this case. Below is a minimal project to test it out and any advice is much appreciated!
Result result = new Result();
//result.Identifier = "Passed";
result = null;
bool HasPassed = (result != null && result.Identifier.Equals("Passed")) ? true : false;
public class Result
{
public string Identifier { get; set; }
}