-2

I have come to a point where I need to create a script on my new employer.

The problem is, one part of algorithm that I need to script is directly calculated inside the visual studio.

The line is

decimal averageCaseSize = totalPolicy == 0 ? 0 : (totalPremium / totalPolicy);

Does anyone know what is the meaning of == 0 ? 0 :

Hope I am asking on the right site.

Thanks a lot.

439
  • 720
  • 2
  • 7
  • 14

1 Answers1

2

With a ternary operator, this could be accomplished with the following.

decimal averageCaseSize = totalPolicy == 0 ? 0 : (totalPremium / totalPolicy);

In long form it looks like this-

if(totalPolicy == 0)
    decimal averageCaseSize = 0
else
    decimal averageCaseSize = (totalPremium / totalPolicy);
439
  • 720
  • 2
  • 7
  • 14