Exam Prep Questions

Question 1

You want to view the trace output for your Web application. The Web application root directory is at http://localhost/myapplication . Which of the following URLs would you type in Internet Explorer to view the trace results for this application?

  • A. http://localhost/myapplication?trace=true

  • B. http://localhost/myapplication/trace

  • C. http://localhost/myapplication?trace=ON

  • D. http://localhost/myapplication/trace.axd

A1:

The correct answer is D. You can view the trace results by requesting trace.axd from the application directory. Answers A, B, and C are incorrect because these URLs do not reveal trace results for an application.

Question 2

While debugging your ASP.NET Web form, you want to display the trace messages as part of the page execution details. Which of the following methods should you use? (Select two.)

  • A. TraceContext.Write()

  • B. TraceContext.Warn()

  • C. System.Diagnostics.Trace.Write()

  • D. System.Diagnostics.Debug.Write()

A2:

The correct answers are A and B. The trace messages written using the TraceContext.Write() and TraceContext.Warn() methods can append trace messages to other tracing information in the page output. Answers C and D are incorrect because the trace messages written using the Trace.Write() and Debug.Write() methods of the System.Diagnostics namespace are written to the Output window of Visual Studio .NET by default.

Question 3

You have added the following statement to the Load event handler of a single-page Web application:

 Trace.Listeners.Add(new TextWriterTraceListener ("TraceLog.txt")) 

Which of the following statements are true with respect to program execution? (Select all that apply.)

  • A. TextWriterTraceListner will listen to all messages generated by the methods of the Debug and Trace classes.

  • B. TextWriterTraceListner will listen to only the messages generated by the methods of the Trace classes.

  • C. All the trace messages will be stored in a file named TraceLog.txt .

  • D. The trace messages are displayed in the Output window while running the program in either the Debug or Release configuration.

A3:

The correct answers are A, C, and D. When the new listener is added to the Trace class, it is also added to the Listeners collection. The Listeners collection already has a DefaultTraceListener object that sends messages to the Output window. Therefore, you have messages in TraceLog.txt as well as in the Output window. Answer B is incorrect because, when you add a listener to the Trace.Listeners collection, it listens to the messages generated by both the Trace and Debug classes.

Question 4

You are asked to implement tracing in a Web application such that the application should display both warning and error messages when the application is run using the Debug configuration and should display only an error message when it is run using the Release configuration of Visual C# .NET. Which of the following code segments best solves this requirement?

  • A.

     TraceSwitch traceSwitch = new TraceSwitch(     "MySwitch", "Error and Warning Switch"); #if DEBUG    traceSwitch.Level = TraceLevel.Warning; #else    traceSwitch.Level = TraceLevel.Error; #endif Trace.WriteLineIf(traceSwitch.TraceWarning, "Warning Message"); Trace.WriteLineIf(traceSwitch.TraceError, "Error Message"); 
  • B.

     TraceSwitch traceSwitch = new TraceSwitch(     "MySwitch", "Error and Warning Switch"); #if DEBUG    traceSwitch.Level = TraceLevel.Warning; #else    traceSwitch.Level = TraceLevel.Error; #endif Debug.WriteLineIf(traceSwitch.TraceWarning, "Warning Message"); Debug.WriteLineIf(traceSwitch.TraceError, "Error Message"); 
  • C.

     TraceSwitch traceSwitch = new TraceSwitch(     "MySwitch", "Error and Warning Switch"); #if TRACE    traceSwitch.Level = TraceLevel.Warning; #else    traceSwitch.Level = TraceLevel.Error; #endif Trace.WriteLineIf(traceSwitch.TraceWarning, "Warning Message"); Trace.WriteLineIf(traceSwitch.TraceError, "Error Message"); 
  • D.

     TraceSwitch traceSwitch = new TraceSwitch(      "MySwitch", "Error and      Warning Switch"); #if TRACE    traceSwitch.Level = TraceLevel.Error; #else     traceSwitch.Level = TraceLevel.Warning; #endif Trace.WriteLineIf(traceSwitch.TraceWarning, "Warning Message"); Trace.WriteLineIf(traceSwitch.TraceError, "Error Message"); 
A4:

The correct answer is A. Because the DEBUG symbol is defined in the Debug configuration, the Level property of traceSwitch is set to TraceLevel.Warning . This causes both the TraceWarning and TraceError properties of the TraceSwitch object to evaluate to true , resulting in both of the messages being displayed. In the Release configuration where only the TRACE symbol is defined, the Level property of traceSwitch is set to TraceLevel.Error . This causes the TraceWarning property to return a false value and the TraceError property to return a true value, so only the error messages is displayed. Answer B is incorrect because the Debug class is used to generate the output and therefore no messages is displayed in the Release configuration. Answer C is incorrect because it does the reverse by displaying warning and error messages in the Release configuration and only warning messages in the Debug configuration. Answer D is incorrect because the TRACE symbol is defined in both the Debug and Release configurations, resulting in the display of only error messages for both the Debug and Release configurations.

Question 5

You are developing an ASP.NET Web application, and your application's web.config file has the following code:

 <system.diagnostics>     <switches>         <add name="TraceLevelSwitch" value="3" />     </switches> </system.diagnostics> 

You have written the following tracing code in your program:

 static TraceSwitch traceSwitch = new TraceSwitch(     "TraceLevelSwitch", "Trace the application"); [Conditional("DEBUG")] private void Method1() {   Trace.WriteLineIf(traceSwitch.TraceError, "Message 1",   "Message 2"); } [Conditional("TRACE")] private void Method2() {     Trace.WriteLine("Message 3"); } private void btnCalculate_Click(object sender, System.EventArgs e) {     if(traceSwitch.TraceWarning){        Trace.WriteLine("Message 10");        Method1();     }     else{        Trace.WriteLineIf(traceSwitch.TraceInfo,        "Message 20");        Method2();     }     if (traceSwitch.TraceError)        Trace.WriteLineIf(traceSwitch.TraceInfo,        "Message 30");        Trace.WriteLineIf(traceSwitch.TraceVerbose,        "Message 40"); } 

Which tracing output will be generated when you run your program in debug mode and click the btnCalculate button?

  • A.

     Message 10 Message 1 Message 2 Message 30 
  • B.

     Message 10 Message 2: Message 1 Message 30 
  • C.

     Message 10 Message 2 Message 30 Message 40 
  • D.

     Message 20 Message 3 Message 30 Message 40 
A5:

The correct answer is B. The value for the TraceLevelSwitch is 3 , which causes the Level property to be set to TraceLevel. Info . This causes the TraceError , TraceWarning , and TraceInfo properties of the traceSwitch to be true ; only the TraceVerbose property evaluates to false . Answer A is incorrect because the third parameter of the WriteLineIf() method in the Method1() is used to categorize the output by specifying its value, followed by a colon ( : ) and then the trace message. Answers C and D are incorrect because the TraceVerbose property evaluates to false , so the string Message 40 will never be displayed.

Question 6

You have following segment of code in your program:

 EventLogTraceListener traceListener =     new EventLogTraceListener("TraceLog"); Trace.Listeners.Add(traceListener); Debug.Listeners.Add(traceListener); Trace.WriteLine("Sample Message"); Debug.WriteLine("Sample Message"); 

When you debug the program through Visual Studio .NET, how many times would the message Sample Message be written to the TraceLog ?

  • A. 1

  • B. 2

  • C. 3

  • D. 4

A6:

The correct answer is D. The message SampleMessage will be written four times. In this question, two instances of EventLogTraceListeners are added to the Listeners collection. Therefore, any message generated by the Trace and Debug classes will be listened to twice because they share the same Listeners collection. Because the program is running in Debug mode, both the Trace and Debug statements will be executed. The net effect is that the messages written by the Trace.WriteLine() and Debug.WriteLine() methods will be both written twice, making four entries in the trace log. Therefore, answers A, B, and C are incorrect.

Question 7

You are debugging a Web form that involves long calculation and iterations. You want to break into the code to watch the values of variables whenever the value of intValue changes in the following statement:

 intValue = ProcessValue(intValue); 

Which of the following options will quickly allow you to achieve this?

  • A. Run the application using step execution mode. Then use the Step Out key to step out of the execution from the ProcessValue() method. Use the Immediate window to display the value of intValue before and after this line of code executes.

  • B. Set a breakpoint at the given statement and set the Hit Count option Break when Hitcount Is Equal to 1.

  • C. Set the breakpoint at the given statement. In the Breakpoint Condition dialog box, enter intValue != intValue and check the Is True option.

  • D. Set the breakpoint at the given statement. In the Breakpoint Condition dialog box, enter intValue and check the Has Changed option.

A7:

The correct answer is D. When you want to break into the code when the value of a variable changes, the quickest approach is to set a conditional breakpoint and check the Has Changed option. Answer A is incorrect because this solution requires you to constantly monitor the values of the variables. Answer B is incorrect because the hit count counts only the number of times a statement has been executed. Answer C is incorrect because an inequality comparison of a variable with itself always results in a false value and therefore the breakpoint will never be hit.

Question 8

Which of the following statements are true for remote debugging of processes? (Select all that apply.)

  • A. Both the local as well as the remote machine should have Visual Studio .NET installed.

  • B. Only the local machine needs Visual Studio .NET.

  • C. Remote Components Setup is required on the local machine.

  • D. Remote Components Setup is required on the remote machine.

A8:

The correct answers are B and D. You need to have Visual Studio .NET on the local machine to debug the remote processes. In addition, you need to run a Remote Components Setup on the remote machine. Answer A is incorrect because, for remote debugging, Visual Studio .NET is not required on the remote machine. Answer C is incorrect because, for remote debugging, Remote Components Setup is not required on the local machine.

Question 9

While you are debugging in Visual Studio .NET, you want to watch only the values of those variables you are using in the current statement and its previous statement. Which of the following debugger windows is the easiest way to watch these variables?

  • A. Autos

  • B. Locals

  • C. This

  • D. Watch

A9:

The correct answer is A. The Autos window gives you the most convenient access because it automatically displays the names and values of all the variables in the current statement and the previous statement at every step. Answer B is incorrect because the Locals window displays the value of all the local variables in the current scope. Answer C is incorrect because the This window displays only the data members of the object associated with the current method. Answer D is incorrect because the Watch window displays only the value of the selected variables and expressions.

Question 10

You have been developing a Web application for an airline's ticketing system. The Web form in the Web application also has some client-side scripting code written in JavaScript. You want to step through this code to understand its execution. Which of the following steps would you take? (Select three.)

  • A. Set a breakpoint in the client-side scripting code where you want the application to pause execution.

  • B. Attach the debugger to the aspnet_wp.exe process executing the Web form.

  • C. Attach the debugger to the iexplore.exe process displaying the Web form.

  • D. Enable script debugging in Internet Explorer.

A10:

The correct answers are A, C, and D. To enable client-side script debugging, you need to set a breakpoint in the client-side script. In addition to this, you must attach the debugger to the iexplore.exe process running the Web form and enable script debugging in Internet Explorer. Answer B is incorrect because client-side scripts execute inside a browser on the client and not on the server.



MCAD Developing and Implementing Web Applications with Visual C#. NET and Visual Studio. NET (Exam [... ]am 2)
MCAD Developing and Implementing Web Applications with Visual C#. NET and Visual Studio. NET (Exam [... ]am 2)
ISBN: 789729016
EAN: N/A
Year: 2005
Pages: 191

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net