Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could someone interpret this line of code?

Tags:

c#

int salesTeamId = person == null ? -1 : person.SalesTeam.Id;

From what I can piece together:

  1. int SalesTeamId is a variable and person is being assigned to the variable.

After that I'm lost. Any guidance?

like image 748
MissioDei Avatar asked Oct 27 '11 22:10

MissioDei


People also ask

How do you explain a line of code?

A line of code (LOC) is any line of text in a code that is not a comment or blank line, and also header lines, in any case of the number of statements or fragments of statements on the line. LOC clearly consists of all lines containing the declaration of any variable, and executable and non-executable statements.

What is the purpose of this line of code?

Source lines of code (SLOC), also known as lines of code (LOC), is a software metric used to measure the size of a computer program by counting the number of lines in the text of the program's source code.


1 Answers

This is a ternary statement. I translated it into a if/else block for you for readability.

int salesTeamId;

if(person == null)
{
   salesTeamId = -1;
}
else
{
   salesTeamId = person.SalesTeam.Id;
}
like image 116
Akron Avatar answered Sep 24 '22 23:09

Akron