Which code segment should you use?

You are using the Microsoft Visual Studio 2005 IDE to examine the output of a method that returns a string.
You assign the output of the method to a string variable named fName. You need to write a code segment that prints the following on a single line The message:
“Test Failed: “
The value of fName if the value of fName does not equal “Certkiller” You also need to ensure that the code segment simultaneously facilitates uninterrupted execution of the application.
Which code segment should you use?

You are using the Microsoft Visual Studio 2005 IDE to examine the output of a method that returns a string.
You assign the output of the method to a string variable named fName. You need to write a code segment that prints the following on a single line The message:
“Test Failed: “
The value of fName if the value of fName does not equal “Certkiller” You also need to ensure that the code segment simultaneously facilitates uninterrupted execution of the application.
Which code segment should you use?

A.
Debug.Assert(fName == “CertKiller”, “Test Failed: “, fName);

B.
Debug.WriteLineIf(fName != “CertKiller”, fName, “Test Failed: “);

C.
if (fName != “Certkiller”) {
Debug.print(“Test Failed: “);
Debug.print(fName);
}

D.
if (fName != “Certkiller”) {
Debug.WriteLine(“Test Failed: “);
Debug.WriteLine(fName);
}

Explanation:
Debug.WriteLineIf() will conditionally write the “Test Failed”, it will not interrupt execution of the application.
A an Assert will stop execution of the application in debug mode if the condition is not met.
C & D could be used but they execute in the release configurations



Leave a Reply 0

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