exam questions

Exam 70-486 All Questions

View all questions & answers for the 70-486 exam

Exam 70-486 topic 1 question 106 discussion

Actual exam question from Microsoft's 70-486
Question #: 106
Topic #: 1
[All 70-486 Questions]

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);
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️
There's "Microsoft Code Contracts" where you use syntax like Contract.Requires(obj != null) which gives you runtime and compile checking. Contract.Requires specifies a precondition contract for an enclosing method or property.
Incorrect Answers:
A: Contract.Assume instructs code analysis tools to assume that the specified condition is true, even if it cannot be statically proven to always be true.
C: Contract.Ensures specifies a postcondition contract for the enclosing method or property.
D: Contract.Invariant specifies an invariant contract for the enclosing method or property, and displays a message if the condition for the contract fails.
References:
https://msdn.microsoft.com/en-us/library/system.diagnostics.contracts.contract(v=vs.110).aspx

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
arohh
4 years, 5 months ago
Answer is: Requires https://stackoverflow.com/questions/4758460/code-contracts-assume-vs-requires
upvoted 2 times
...
murat12345
4 years, 6 months ago
It is A right?
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago