Which code segment should you insert at line 03?

You are developing an ASP.NET MVC application. The application includes the following method. Line
numbers are included for reference only.

The application calls the GenerateMessage method before displaying each page.
The GenerateMessage method throws NullReferenceException exceptions.
You need to use Code Contracts to prevent the exceptions.
Which code segment should you insert at line 03?

You are developing an ASP.NET MVC application. The application includes the following method. Line
numbers are included for reference only.

The application calls the GenerateMessage method before displaying each page.
The GenerateMessage method throws NullReferenceException exceptions.
You need to use Code Contracts to prevent the exceptions.
Which code segment should you insert at line 03?

A.
Contract.Assume(userAgent !=null);

B.
Contract.Requires(userAgent !=null);

C.
Contract.Ensures(userAgent !=null);

D.
Contract.Invariant(userAgent !=null);

Explanation:
There’s”Microsoft Code Contracts” where you use syntax like Contract.Requires(obj != null) which gives youruntime and compile checking. Contract.Requires specifies a precondition contract for an enclosing method or
property.



Leave a Reply 1

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


Mario

Mario

Precondition -> require -> on input
Invariant -> Invariant -> anytime
Postcondition -> ensure -> on output