Which code segment should you insert at line 08?

You are developing an application that uses the Microsoft ADO.NET Entity Framework to retrieve
order information from a Microsoft SQL Server database. The application includes the following
code. (Line numbers are included for reference only.)

The application must meet the following requirements:
Return only orders that have an OrderDate value other than null.

Return only orders that were placed in the year specified in the OrderDate property or in a later
year.
You need to ensure that the application meets the requirements.
Which code segment should you insert at line 08?

You are developing an application that uses the Microsoft ADO.NET Entity Framework to retrieve
order information from a Microsoft SQL Server database. The application includes the following
code. (Line numbers are included for reference only.)

The application must meet the following requirements:
Return only orders that have an OrderDate value other than null.

Return only orders that were placed in the year specified in the OrderDate property or in a later
year.
You need to ensure that the application meets the requirements.
Which code segment should you insert at line 08?

A.
Where order.OrderDate.Value != null && order.OrderDate.Value.Year > = year

B.
Where order.OrderDate.Value = = null && order.OrderDate.Value.Year = = year

C.
Where order.OrderDate.HasValue && order.OrderDate.Value.Year = = year

D.
Where order.OrderDate.Value.Year = = year

Explanation:
*For the requirement to use an OrderDate value other than null use:
OrderDate.Value != null
*For the requirement to use an OrderDate value for this year or a later year use:
OrderDate.Value>= year



Leave a Reply 4

Your email address will not be published. Required fields are marked *

two − one =


rao

rao

At run time if orderdate is null all the code throw exception.
The only option which not throw any exception is:
Where order.OrderDate.HasValue && order.OrderDate.Value.Year = = year

but the second condition would be order.OrderDate.Value.Year >= year

Guest

Guest

C, they forgot a >= at the end. This is the only one with a “has value”. Accessing DateTime?.Value even if it is null throws an “invalid operations exception”.

Najlepszy Programista Swiata

Najlepszy Programista Swiata

there is no correct answer

Ashraf

Ashraf

It must be C … OrderDate is set to be Nullable (DateTime?) which will cause exception when using OrderDate.Value if OrderDate is Null.