exam questions

Exam 70-483 All Questions

View all questions & answers for the 70-483 exam

Exam 70-483 topic 2 question 130 discussion

Actual exam question from Microsoft's 70-483
Question #: 130
Topic #: 2
[All 70-483 Questions]

You are testing an application. The application includes methods named CalculateInterest and LogLine. The CalculateInterest() method calculates loan interest. The LogLine() method sends diagnostic messages to a console window.
The following code implements the methods. (Line numbers are included for reference only.)

You have the following requirements:
✑ The CalculateInterest() method must run for all build configurations.
✑ The LogLine() method must run only for debug builds.
You need to ensure that the methods run correctly.
What are two possible ways to achieve this goal? (Each correct answer presents a complete solution. Choose two.)

  • A. Insert the following code segment at line 01: #region DEBUG Insert the following code segment at line 10 :#endregion
  • B. Insert the following code segment at line 01: [Conditional("DEBUG")]
  • C. Insert the following code segment at line 05 :#region DEBUG Insert the following code segment at line 07: #endregion
  • D. Insert the following code segment at line 10: [Conditional("DEBUG")]
  • E. Insert the following code segment at line 01: #if DEBUG Insert the following code segment at line 10: #endif
  • F. Insert the following code segment at line 10: [Conditional("RELEASE")]
  • G. Insert the following code segment at line 05: #if DEBUG
Show Suggested Answer Hide Answer
Suggested Answer: DG 🗳️
D: Also, it's worth pointing out that you can use [Conditional("DEBUG")] attribute on methods that return void to have them only executed if a certain symbol is defined. The compiler would remove all calls to those methods if the symbol is not defined:
[Conditional("DEBUG")]
void PrintLog() {
Console.WriteLine("Debug info");
}
void Test() {
PrintLog();
}
G: When the C# compiler encounters an #if directive, followed eventually by an #endif directive, it will compile the code between the directives only if the specified symbol is defined. Unlike C and C++, you cannot assign a numeric value to a symbol; the #if statement in C# is Boolean and only tests whether the symbol has been defined or not. For example,
#define DEBUG
#if DEBUG
Console.WriteLine("Debug version");
#endif
Reference: http://stackoverflow.com/questions/2104099/c-sharp-if-then-directives-for-debug-vs-release

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
Mitsoshima
Highly Voted 5 years, 11 months ago
Note: To accept G as a correct answer, you have to add an #endif statement at line 7 (as it is mentioned in the explanation)
upvoted 20 times
thiemamd
4 years, 10 months ago
I Agree
upvoted 4 times
...
...
supersunny
Highly Voted 5 years, 10 months ago
D,G is correct
upvoted 7 times
...
HgstExam
Most Recent 4 years, 9 months ago
D,C is correct (not G). missing #endif statement at line 7
upvoted 2 times
Damage_San
4 years, 8 months ago
defining a region won't stop the code from executing
upvoted 4 times
...
Kilsimon
4 years, 8 months ago
It is true that G is missing the #endif, but #region does absolutely nothing for this case.
upvoted 2 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 ...