Skip to main content
deleted 27 characters in body
Source Link
Malachi
  • 29.1k
  • 11
  • 87
  • 188

you create a variable here and use it only once

bool taskExecutionCancelled = IsScripteExecutionCancelled();
if (taskExecutionCancelled)
{
    tokenSource.Cancel();
}

I would just use the method in the if statement, like

if (IsScripteExecutionCancelled())
{
    tokenSource.Cancel();
}

if you were going to use this value somewhere else and didn't want it evaluated again, then you could assign it to a variable, but then you need to keep in mind that calling the methodvariable will not run the method every time that variable is called.

you create a variable here and use it only once

bool taskExecutionCancelled = IsScripteExecutionCancelled();
if (taskExecutionCancelled)
{
    tokenSource.Cancel();
}

I would just use the method in the if statement, like

if (IsScripteExecutionCancelled())
{
    tokenSource.Cancel();
}

if you were going to use this value somewhere else and didn't want it evaluated again, then you could assign it to a variable, but then you need to keep in mind that the method will not run the method every time that variable is called.

you create a variable here and use it only once

bool taskExecutionCancelled = IsScripteExecutionCancelled();
if (taskExecutionCancelled)
{
    tokenSource.Cancel();
}

I would just use the method in the if statement, like

if (IsScripteExecutionCancelled())
{
    tokenSource.Cancel();
}

if you were going to use this value somewhere else and didn't want it evaluated again, then you could assign it to a variable, but then you need to keep in mind that calling the variable will not run the method.

Source Link
Malachi
  • 29.1k
  • 11
  • 87
  • 188

you create a variable here and use it only once

bool taskExecutionCancelled = IsScripteExecutionCancelled();
if (taskExecutionCancelled)
{
    tokenSource.Cancel();
}

I would just use the method in the if statement, like

if (IsScripteExecutionCancelled())
{
    tokenSource.Cancel();
}

if you were going to use this value somewhere else and didn't want it evaluated again, then you could assign it to a variable, but then you need to keep in mind that the method will not run the method every time that variable is called.