Let's say we are building a game in Unity, and every single frame we want to check whether or not the player is null.
I know this is NOT optimal, but I just want to show an example to state my question.
// Update is called once per frame
private void Update()
{
if (player != null)
{
player.Move();
}
}
According to Jetbrains, we should avoid null comparisons against UnityEngine.Object subclasses, since it's a very expensive thing to do. Especially if we do it EVERY frame (which could be 100 times per second).
So I decide to ask Rider to check Player against null in the less expensive way possible. Rider decides to refactor my code to this:
// Update is called once per frame
private void Update()
{
if (player is { } && player)
{
player.Move();
}
}
I'm kind of new to C#, and don't really understand why it doesn't suffice with:
// Update is called once per frame
private void Update()
{
if (player)
{
player.Move();
}
}
Why is Rider comparing Player to a pair of empty brackets as well?