Q1. - (Topic 2)
You are developing an application that uses a .config file.
The relevant portion of the .config file is shown as follows:
You need to ensure that diagnostic data for the application writes to the event log by using the configuration specified in the .config file.
What should you include in the application code?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: A
Explanation: Explanation
http://msdn.microsoft.com/en-us/library/vstudio/system.diagnostics.eventlogtracelistener
Public static void Main(string[] args) {
Create a trace listener for the event log.
EventLogTraceListener myTraceListener = new
EventLogTraceListener("myEventLogSource");
Add the event log trace listener to the collection.
Trace.Listeners.Add(myTraceListener);
// Write output to the event log.
Trace.WriteLine("Test output");
}
Q2. - (Topic 2)
You have the following code (line numbers are included for reference only):
You need to ensure that new instances of Connection can be created only by other classes by calling the Create method. The solution must allow classes to inherit from Connection.
What should you do?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: B
Explanation: The following list provides the main features of a static class:
* Contains only static members.
* Cannot be instantiated.
* Is sealed.
* Cannot contain Instance Constructors.
Creating a static class is therefore basically the same as creating a class that contains only static members and a private constructor. A private constructor prevents the class from being instantiated.
Reference: Static Classes and Static Class Members (C# Programming Guide)
https://msdn.microsoft.com/en-us/library/79b3xss3.aspx
Q3. - (Topic 2)
You are modifying an existing application that manages employee payroll. The application includes a class named PayrollProcessor. The PayrollProcessor class connects to a payroll database and processes batches of paychecks once a week.
You need to ensure that the PayrollProcessor class supports iteration and releases database connections after the batch processing completes.
Which two interfaces should you implement? (Each correct answer presents part of the complete solution. Choose two.)
A. IEquatable
B. IEnumerable
C. IDisposable
D. IComparable
Answer: B,C
Explanation: IEnumerable IDisposable Interface Exposes an enumerator, which supports a simple iteration over a non-generic collection.
Defines a method to release allocated resources.
The primary use of this interface is to release unmanaged resources.
Q4. - (Topic 2)
You need to write a console application that meets the following requirements:
. If the application is compiled in Debug mode, the console output must display Entering debug mode. . If the application is compiled in Release mode, the console output must display Entering release mode.
Which code should you use?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: D
Explanation: #elif lets you create a compound conditional directive. The #elif expression will be evaluated if neither the preceding #if (C# Reference) nor any preceding, optional, #elif directive expressions evaluate to true. If a #elif expression evaluates to true, the compiler evaluates all the code between the #elif and the next conditional directive. For example: #define VC7 //... #if debug Console.Writeline("Debug build"); #elif VC7 Console.Writeline("Visual Studio 7"); #endif
Incorrect: Not B:
* System.Reflection.Assembly.GetExecutingAssembly Method Gets the assembly that contains the code that is currently executing.* Assembly.IsDefined Method Indicates whether or not a specified attribute has been applied to the assembly.
* System.Dignostics.Debugger Class Enables communication with a debugger.
Property: IsAttached
Gets a value that indicates whether a debugger is attached to the process.
Q5. DRAG DROP - (Topic 1)
You are developing an application that implements a set of custom exception types. You declare the custom exception types by using the following code segments:
The application includes a function named DoWork that throws .NET Framework exceptions and custom exceptions. The application contains only the following logging methods:
The application must meet the following requirements:
. When ContosoValidationException exceptions are caught, log the information by using the static void Log (ContosoValidationException ex) method. . When ContosoDbException or other ContosoException exceptions are caught, log the information by using the static void Log(ContosoException ex) method.
You need to meet the requirements.
How should you complete the relevant code? (To answer, drag the appropriate code segments to the correct locations in the answer area. Each code segment may be used once, more than once, or not at all. You may need to drag the split bar between panes or scroll to view content.)
Answer:
Q6. - (Topic 2)
You have the following code:
You need to retrieve all of the numbers from the items variable that are greater than 80. Which code should you use?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: B
Explanation: Example: All number larger than 15 from a list using the var query = from num in numbers... contstruct:
var largeNumbersQuery = numbers2.Where(c => c > 15);
Reference: How to: Write LINQ Queries in C#
https://msdn.microsoft.com/en-us/library/bb397678.aspx
Q7. - (Topic 1)
You are developing an application that includes the following code segment. (Line numbers are included for reference only.)
You need to ensure that the application accepts only integer input and prompts the user each time non-integer input is entered.
Which code segment should you add at line 19?
A. If (!int.TryParse(sLine, out number))
B. If ((number = Int32.Parse(sLine)) == Single.NaN)
C. If ((number = int.Parse(sLine)) > Int32.MaxValue)
D. If (Int32.TryParse(sLine, out number))
Answer: A
Explanation:
B and C will throw exception when user enters non-integer value. D is exactly the opposite what we want to achieve.
Int32.TryParse - Converts the string representation of a number to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. http://msdn.microsoft.com/en-us/library/f02979c7.aspx
Q8. HOTSPOT - (Topic 2)
You have the following code:
For each of the following statements, select Yes if the statement is true. Otherwise, select No.
Answer:
Q9. HOTSPOT - (Topic 2)
You are developing the following classes named:
Class1
Class2
Class3
All of the classes will be part of a single assembly named Assembly.dll. Assembly.dll will be used by multiple applications.
All of the classes will implement the following interface, which is also part ofAssembly.dll:
public interface Interface1 { void Method1(decimal amount); void Method2(decimal amount); }
You need to ensure that the Method2 method for the Class3 class can be executed only when instances of the class are accessed through the Interface1 interface. The solution must ensure that calls to the Method1 method can be made either through the interface or through an instance of the class.
Which signature should you use for each method? (To answer, select the appropriate signature for each method in the answer area.)
Answer:
Q10. DRAG DROP - (Topic 1)
You are implementing a method that creates an instance of a class named User. The User class contains a public event named Renamed. The following code segment defines the Renamed event:
Public event EventHandler<RenameEventArgs> Renamed;
You need to create an event handler for the Renamed event by using a lambda expression.
How should you complete the relevant code? (To answer, drag the appropriate code segments to the correct locations in the answer area. Each code segment may be used once, more than once, or not at all. You may need to drag the split bar between panes or scroll to view content.)
Answer:
Q11. - (Topic 2)
You have the following code (line numbers are included for reference only):
You need to ensure that if an exception occurs, the exception will be logged. Which code should you insert at line 28?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: A
Explanation: * XmlWriterTraceListener
Directs tracing or debugging output as XML-encoded data to a TextWriter or to a Stream,
such as a FileStream.
Q12. - (Topic 2)
You are developing an application that will process personnel records.
The application must encrypt highly sensitive data.
You need to ensure that the application uses the strongest available encryption.
Which class should you use?
A. System.Security.Cryptography.DES
B. System.Security.Cryptography.Aes
C. System.Security.Cryptography.TripleDES
D. System.Security.Cryptography.RC2
Answer: B
Q13. DRAG DROP - (Topic 1)
You are developing an application that includes a class named Warehouse. The Warehouse class includes a static property named Inventory- The Warehouse class is defined by the following code segment. (Line numbers are included for reference only.)
You have the following requirements:
Initialize the _inventory field to an Inventory instance.
Initialize the _inventory field only once.
Ensure that the application code acquires a lock only when the _inventory object must be instantiated.
You need to meet the requirements.
Which three code segments should you insert in sequence at line 09? (To answer, move the appropriate code segments from the list of code segments to the answer area and arrange them in the correct order.)
Answer:
Q14. - (Topic 2)
You need to write a console application that meets the following requirements:
. If the application is compiled in Debug mode, the console output must display Entering debug mode. . If the application is compiled in Release mode, the console output must display Entering release mode.
Which code should you use?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: B
Explanation: 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
Q15. DRAG DROP - (Topic 2)
You are developing a C# application. The application includes a class named Rate. The following code segment implements the Rate class:
You define a collection of rates named rateCollection by using the following code segment:
Collection<Rate> rateCollection = new Collection<Rate>() ;
The application receives an XML file that contains rate information in the following format:
You need to parse the XML file and populate the rateCollection collection with Rate objects.
You have the following code: Which code segments should you include in Target 1, Target 2, Target 3 and Target 4 to complete the code? (To answer, drag the appropriate code segments to the correct targets in the answer area. Each code segment may be used once, more than once, or not at all. You may need to drag the split bar between panes or scroll to view content.)
Answer: