Microsoft .NET Framework, Application Development Foundation

42
TS: Microsoft .NET Framework, Application Development Foundation Question Number (ID) : 1 (536P_1.3_05) Which of the following types CANNOT be marshaled between managed and unmanaged processes? 1. Arrays 2. Generic types 3. Strings 4. Structures 5. Boolean types 6. Delegates Explanation: Generic types cannot be marshaled between managed and unmanaged memory. Arrays, boolean types, char types, delegates, classes, objects, strings, and structures can be marshaled. Objective: Developing applications that use system types and collections Sub Objective(s): Improve type safety and application performance in a .NET Framework application by using generic collections. References: MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, Second Edition Chapter 13 - Lessons 1 and 2 Default Marshaling Behavior MSDN Library Link: http://msdn.microsoft.com/library/zah6xy75.aspx TS: Microsoft .NET Framework, Application Development Foundation Question Number (ID) : 2 (536P_2.1_03) What is the preferred way for a service to interact with a user? 1. By opening a Web browser 2. By opening a dialog box 3. By writing a message to a text file 4. By writing an event to the event log Explanation: Services do not have a user interface. Therefore, they cannot directly interact with the user by opening a dialog box or Web browser. Instead, you should write events to the event log. Although you could write messages to a text file, the event log is easier to manage, especially in enterprise environments. Objective: Implementing service processes, threading, and application domains in a .NET Framework application Sub Objective(s):

Transcript of Microsoft .NET Framework, Application Development Foundation

Page 1: Microsoft .NET Framework, Application Development Foundation

TS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 1 (536P_1.3_05)Which of the following types CANNOT be marshaled between managed and unmanaged processes?1. Arrays2. Generic types 3. Strings4. Structures5. Boolean types6. Delegates

Explanation:Generic types cannot be marshaled between managed and unmanaged memory.Arrays, boolean types, char types, delegates, classes, objects, strings, and structures can be marshaled.Objective:Developing applications that use system types and collectionsSub Objective(s):Improve type safety and application performance in a .NET Framework application by using generic collections.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 13 - Lessons 1 and 2Default Marshaling BehaviorMSDN LibraryLink: http://msdn.microsoft.com/library/zah6xy75.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 2 (536P_2.1_03)What is the preferred way for a service to interact with a user?1. By opening a Web browser2. By opening a dialog box3. By writing a message to a text file4. By writing an event to the event log

Explanation:Services do not have a user interface. Therefore, they cannot directly interact with the user by opening a dialog box or Webbrowser. Instead, you should write events to the event log. Although you could write messages to a text file, the event log iseasier to manage, especially in enterprise environments.Objective:Implementing service processes, threading, and application domains in a .NET Framework applicationSub Objective(s):Implement, install, and control a service.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 8 - Lesson 3ServiceController ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.serviceprocess.servicecontroller.aspxIntroduction to Windows Service Applications

Page 2: Microsoft .NET Framework, Application Development Foundation

MSDN LibraryLink: http://msdn.microsoft.com/library/d56de412.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 3 (536P_3.2_07)You have derived a custom class from the Installer class. If the user cancels an installation, you need to run special code toremove changes you have made.Which of the following Installer methods would you place the code in?1. Install2. OnCommitting3. Rollback 4. OnRollback5. Commit

Explanation:Use the Rollback method to remove changes made during installation when the install is cancelled.The Install method performs the actual installation.The Commit method finalizes installation changes.The OnCommitting method runs immediately before the Commit method.There is no OnRollback method.Objective:Embedding configuration, diagnostic, management, and installation features into a .NET Framework applicationSub Objective(s):Create a custom Microsoft Windows Installer for .NET components by using the System.Configuration.Install namespace, andconfigure .NET Framework applications by using configuration files, environment variables, and the .NET FrameworkConfiguration tool (Mscorcfg.msc).References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 9 - Lesson 2Installer ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.configuration.install.installer.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 4 (536P_4.2_04)Given the following C# class, which of the following files represents how an instance of that class would be serialized using theXmlSerializer class?public class ShoppingCartItem{public Int32 productId;public decimal price;public Int32 quantity;public decimal total;public ShoppingCartItem(){}}1. <?xml version="1.0" ?><productId>100</productId><price>10.25</price>

Page 3: Microsoft .NET Framework, Application Development Foundation

<quantity>2</quantity><total>20.50</total>2. <?xml version="1.0" ?><ShoppingCartItem productId="100" price="10.25" quantity="2"total="20.50"></ShoppingCartItem>3. <?xml version="1.0" ?><ShoppingCartItem><productId>100</productId><price>10.25</price><quantity>2</quantity><total>20.50</total></ShoppingCartItem>

4. <?xml version="1.0" ?><ShoppingCartItem><productId>100</productId><price>10.25</price><quantity>2</quantity></ShoppingCartItem>

Explanation:By default, XmlSerializer serializes all members as Extensible Markup Language (XML) elements.XmlSerializer serializes members as attributes only if each member has the XmlAttribute attribute.XmlSerializer would ignore the total member only if it had the XmlIgnore attribute.XmlSerializer creates an element for the class and makes each member a subelement within the class element.Objective:Implementing serialization and input/output functionality in a .NET Framework applicationSub Objective(s):Control the serialization of an object into XML format by using the System.Xml.Serialization namespace.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 5 - Lesson 2Basic SerializationMSDN LibraryLink: http://msdn.microsoft.com/library/4abbf6k0.aspxXmlSerializer ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.xml.serialization.xmlserializer.aspxIntroducing XML SerializationMSDN LibraryLink: http://msdn.microsoft.com/library/182eeyhh.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 5 (536P_5.4_03)You are writing an assembly that verifies that files have not been modified since they were initially scanned. The checksumswill be stored in a text file.Which hashing algorithms could you use to prevent an attacker from modifying both the file and the checksum? (Choose allthat apply.)1. SHA2562. HMACSHA1

Page 4: Microsoft .NET Framework, Application Development Foundation

3. MD54. MACTripleDES

Explanation:HMACSHA1 and MACTripleDES are keyed hashing algorithms, which protect against modification of the hash by encrypting itthrough the use of a secret key that both the sender and receiver must have.MD5 and SHA256 are unkeyed hashing algorithms, which can be modified by an unauthorized user without being detectedeasily.Objective:Improving the security of .NET Framework applications by using the .NET Framework security featuresSub Objective(s):Encrypt, decrypt, and hash data by using the System.Security.Cryptography classes.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 12 - Lesson 3Cryptography OverviewMSDN LibraryLink: http://msdn.microsoft.com/library/92f9ye3s.aspxKeyedHashAlgorithm ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.security.cryptography.keyedhashalgorithm.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 6 (536P_6.3_03)You have created a Type object.Which method would you call to retrieve a collection containing all methods, interfaces, properties, and constructors for theclass?1. Type.GetFields2. Type.GetDefaultMembers3. Type.GetMethods4. Type.GetMembers

Explanation:Type.GetMembers retrieves all members, including methods, interfaces, properties, and constructors.Type.GetFields searches for fields defined by the current type.Type.GetDefaultMembers searches for members defined by the current type whose System.Reflection.DefaultMemberAttributeis set.Type.GetMethods returns a collection containing only methods, and not interfaces or properties.Objective:Implementing interoperability, reflection, and mailing functionality in a .NET Framework applicationSub Objective(s):Implement reflection functionality in a .NET Framework application, and create metadata, Microsoft intermediate language(MSIL), and a PE file by using the System.Reflection.Emit namespace.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 14 - Lesson 1Viewing Type Information

Page 5: Microsoft .NET Framework, Application Development Foundation

MSDN LibraryLink: http://msdn.microsoft.com/library/t0cs7xez.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 7 (536P_7.1_05)Which of the following C# code samples correctly performs a culture-insensitive string comparison?1. string s1 = "Apple";string s2 = "Æble";int r = String.Compare(s1, s2, false,CultureInfo.InvariantCulture);

2. string s1 = "Apple";string s2 = "Æble";int r = String.Compare(s1, s2, false,CultureInfo.CurrentUICulture);3. string s1 = "Apple";string s2 = "Æble";int r = String.Compare(s1, s2, false,CultureInfo.CreateSpecificCulture("da-DK"));4. string s1 = "Apple";string s2 = "Æble";int r = String.Compare(s1, s2, false);

Explanation:By default, string comparisons are culture sensitive. To perform culture-insensitive comparisons, pass theCultureInfo.InvariantCulture parameter.Objective:Implementing globalization, drawing, and text manipulation functionality in a .NET Framework applicationSub Objective(s):Format data based on culture information.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 16 - Lesson 1How to: Use Finally BlocksMSDN LibraryLink: http://msdn.microsoft.com/library/ke0zf0f5.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 8 (536P_1.2_03)You are creating a new collection type that must be iterated using a foreach loop.Which of the following interfaces should you implement? (Choose all that apply.)1. ICollection2. IEqualityComparer3. IDictionaryEnumerator 4. IDictionary5. IEnumerable

Explanation:You must implement IEnumerable or IDictionaryEnumerator when creating a collection for use in a foreach loop.The ICollection interface is the base interface for classes in the System.Collections namespace. It does not support foreachloops.

Page 6: Microsoft .NET Framework, Application Development Foundation

The IDictionary interface is the base interface for nongeneric collections of key/value pairs. It does not support foreach loops.The IEqualityComparer interface supports only equality comparisons and cannot be used in foreach loops.Objective:Developing applications that use system types and collectionsSub Objective(s):Manage a group of associated data in a .NET Framework application by using collections.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 4 - Lesson 1IEnumerable InterfaceMSDN LibraryLink: http://msdn.microsoft.com/en-us/library/system.collections.ienumerable.aspxIDictionaryEnumerator InterfaceMSDN LibraryLink: http://msdn.microsoft.com/en-us/library/system.collections.idictionaryenumerator.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 9 (536P_2.2_09)You are writing a multi-threaded application, and multiple threads need to read and write the same file. At times, a thread willneed to read from the file and then immediately write to the file.What is the most efficient way to handle this in the thread?1. 1. Create a ReaderWriterLock object and call ReaderWriterLock.AcquireWriteLock.2. Perform both the reads and the writes.2. 1. Create a ReaderWriterLock object and call ReaderWriterLock.AcquireReadLock.2. Perform the reads.3. Call ReaderWriterLock.UpgradeToWriterLock and perform the writes.

3. 1. Create a ReaderWriterLock object and call ReaderWriterLock.AcquireReadLock.2. Perform the reads.3. Call ReaderWriterLock.ReleaseLock.4. Call ReaderWriterLock.AcquireWriteLock and perform the writes.4. 1. Create a ReaderWriterLock object and call ReaderWriterLock.AcquireReadLock.2. Perform the reads.3. Call ReaderWriterLock.ReleaseReaderLock.4. Call ReaderWriterLock.AcquireWriteLock and perform the writes.

Explanation:The most efficient way to switch from a read lock to a write lock is to call ReaderWriterLock.UpgradeToWriterLock.You cannot read when you have a write lock.Although you can release a read lock and acquire a write lock, it is not as efficient as using UpgradeToWriterLock.Objective:Implementing service processes, threading, and application domains in a .NET Framework applicationSub Objective(s):Develop multithreaded .NET applications.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 7 - Lesson 1ReaderWriterLock ClassMSDN Library

Page 7: Microsoft .NET Framework, Application Development Foundation

Link: http://msdn.microsoft.com/library/system.threading.readerwriterlock.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 10 (536P_3.4_04)You are writing an application that requires the user to open a second application named Application.exe, make a configurationchange, and then close the second application. You want to start the application automatically for the user and then waitindefinitely until the user closes the application.Which of the following C# code samples accomplishes this?1. Process p = new Process();p.StartInfo.FileName = "Application.exe";p.Start();p.WaitForExit(10000);2. Process p = new Process("Application.exe");p.Start();p.WaitForExit();3. Process p = new Process("Application.exe");p.Start();p.WaitForExit(10000);4. Process p = new Process();p.StartInfo.FileName = "Application.exe";p.Start();p.WaitForExit();

Explanation:To start a new process, first create an instance of the Process class, and then specify the Process.StartInfo.FileNameproperty. Finally, call the Process.Start method. To stop processing until the application closes, call the Process.WaitForExitmethod without specifying a time.You cannot specify an application filename in the Process constructor.Specifying a time for the Process.WaitForExit method causes the runtime to continue execution after the specified time even ifthe application hasn't closed.You cannot specify an application filename in the Process constructor. In addition, specifying a time for theProcess.WaitForExit method causes the runtime to continue execution after the specified time even if the application has notclosed.Objective:Embedding configuration, diagnostic, management, and installation features into a .NET Framework applicationSub Objective(s):Manage system processes and monitor the performance of a .NET application by using the diagnostics functionality ofthe .NET Framework 2.0.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 10 - Lesson 3Process ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.diagnostics.process.aspxTS: Microsoft .NET Framework, Application Development Foundation

Page 8: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 11 (536P_4.2_01)You are responsible for an internal database application. Your organization would now like to send information selectively fromthe database to external customers using Extensible Markup Language (XML) documents. Currently, you have custom classesthat store this information.Which class is the best one to use to write the XML documents?1. StreamWriter2. XmlSerializer 3. TextWriter4. BinaryFormatter

Explanation:XmlSerializer is the most efficient way to write an object to an XML document.BinaryFormatter would write the object to disk, but it would not use XML.TextWriter and StreamWriter could be used to create XML documents, but it would be very inefficient because you would haveto create the XML formatting manually.Objective:Implementing serialization and input/output functionality in a .NET Framework applicationSub Objective(s):Control the serialization of an object into XML format by using the System.Xml.Serialization namespace.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 5 - Lesson 2 and 3Introducing XML SerializationMSDN LibraryLink: http://msdn.microsoft.com/library/182eeyhh.aspxXmlSerializer ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.xml.serialization.xmlserializer.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 12 (536P_5.4_07)You are reviewing a colleague's code for security vulnerabilities.Which of the following System.Security.Cryptography classes indicates that the developer was using weak encryption thatcould potentially be cracked in a short amount of time?1. TripleDES2. DES 3. RijndaelManaged4. RC2

Explanation:The Data Encryption Standard (DES) is a symmetric encryption algorithm that uses relatively short key lengths that arevulnerable to cracking attacks. For that reason, it should be avoided.RijndaelManaged, an implementation of Advanced Encryption Standard (AES), is a strong government encryption standardand is the only .NET Framework symmetric encryption class that is fully managed. All other encryption classes call unmanagedcode. Because of this, RijndaelManaged is the preferred choice when your application will be running in a partially trustedenvironment.

Page 9: Microsoft .NET Framework, Application Development Foundation

RC2 is an encryption standard designed to replace DES that uses variable key sizes. It is more secure than DES.TripleDES is the .NET Framework implementation of the Triple DES symmetric encryption algorithm. It essentially applies theDES algorithm three times. It is approximately twice as strong as standard DES.Objective:Improving the security of .NET Framework applications by using the .NET Framework security featuresSub Objective(s):Encrypt, decrypt, and hash data by using the System.Security.Cryptography classes.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 12 - Lesson 3Cryptography OverviewMSDN LibraryLink: http://msdn.microsoft.com/library/92f9ye3s.aspxSymmetricAlgorithm ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.security.cryptography.symmetricalgorithm.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 13 (536P_6.1_03)You are creating an assembly that references a Component Object Model (COM) object. To ensure that the COM object isavailable and properly referenced, you want to perform early-bound activation.Which of the following C# code samples correctly activates an instance of the MyLib.MyClass coclass?1. using System;using MyLib;public class MyApp {public static void Main(String[] Args) {MyClass mc = new MyClass();// TODO: Complete application}} 2. using System;using MyLib;public class MyApp {public static void Main(String[] Args) {activate MyClass// TODO: Complete application}}3. using System;using MyLib;preload MyLib;public class MyApp {public static void Main(String[] Args) {// TODO: Complete application}}4. using System;using MyLib;public class MyApp {load MyClass;public static void Main(String[] Args) {// TODO: Complete application

Page 10: Microsoft .NET Framework, Application Development Foundation

}}

Explanation:To perform early-bound activation, simply create an instance of the class. When a .NET Framework client creates an instanceof a coclass, the runtime must locate its metadata, regardless of whether the class is a .NET Framework class or a COMcoclass. Metadata must be available at runtime to early-bind to a class. Metadata is not required for late-bound activation.There are no Load, Preload, or Activate keywords.Objective:Implementing interoperability, reflection, and mailing functionality in a .NET Framework applicationSub Objective(s):Expose COM components to the .NET Framework and .NET Framework components to COM.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 13 - Lesson 1Activating a COM ObjectMSDN LibraryLink: http://msdn.microsoft.com/library/7c01w25h.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 14 (536P_7.1_07)Which of the following types would you create an instance of first to define a custom culture?1. CultureAndRegionModifier2. CultureInfo3. CultureAndRegionInfoBuilder 4. CultureTypes

Explanation:The CultureAndRegionInfoBuilder class defines a custom culture that is new or based on an existing culture and region. Thecustom culture can be installed on a computer and subsequently used by any application running on that computer.The CultureInfo class provides information about a specific culture. Once you have defined a custom culture withCultureAndRegionInfoBuilder, you can create a CultureInfo object based on the custom class. However, you must defineCultureAndRegionInfoBuilder first.The CultureAndRegionModifiers enumeration specifies constants that define a CultureAndRegionInfoBuilder object.The CultureTypes enumeration defines the types of culture lists that can be retrieved using CultureInfo.GetCultures.Objective:Implementing globalization, drawing, and text manipulation functionality in a .NET Framework applicationSub Objective(s):Format data based on culture information.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 16 - Lesson 1How to: Create Custom CulturesMSDN Library

Page 11: Microsoft .NET Framework, Application Development Foundation

Link: http://msdn.microsoft.com/library/ms172469.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 15 (536P_1.4_04)In C#, which of the following code samples compiles correctly?1. StringDictionary dict = new StringDictionary();dict["First"] = "1st"; 2. StringDictionary dict = new StringDictionary();dict[4] = 4;3. StringDictionary dict = new StringDictionary();dict[2] = "2";4. StringDictionary dict = new StringDictionary();dict["3"] = 3;

Explanation:When you create an instance of the specialized StringDictionary class, you can set only values that are strings, and you canuse only string indexes. Visual Basic automatically converts values to strings; however, you should still use theStringDictionary class only when both the index and the value are strings.Objective:Developing applications that use system types and collectionsSub Objective(s):Manage data in a .NET Framework application by using specialized collections.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 4 - Lesson 1StringDictionary ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.collections.specialized.stringdictionary.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 16 (536P_2.2_08)Given the following C# code sample, how could you display the contents of the host string in the ProcessDnsInformationmethod?AsyncCallback callBack = new AsyncCallback(ProcessDnsInformation);string host = Console.ReadLine();Dns.BeginGetHostEntry(host, callBack, host);1. static void ProcessDnsInformation(IAsyncResult result){Console.WriteLine(result.AsyncState);}2. static void ProcessDnsInformation(IAsyncResult result){Console.WriteLine((string)result.AsyncState);}

3. static void ProcessDnsInformation(IAsyncResult result, string host){Console.WriteLine(host);}4. static void ProcessDnsInformation(IAsyncResult result){Console.WriteLine(result.ToString());}

Page 12: Microsoft .NET Framework, Application Development Foundation

Explanation:If you provide an AsyncCallback delegate, you can provide an object when creating the asynchronous request. This object isnot processed during the request and is simply passed to the method specified to handle the completed request. The object isstored in IAsyncResult.AsyncState, and you must cast or convert it to the proper type.AsyncCallback delegates always accept a single parameter: an IAsyncResult object.Objective:Implementing service processes, threading, and application domains in a .NET Framework applicationSub Objective(s):Develop multithreaded .NET applications.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 7 - Lesson 1Using an AsyncCallback Delegate to End an Asynchronous OperationMSDN LibraryLink: http://msdn.microsoft.com/library/ms228972.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 17 (536P_3.6_03)You are creating a tool for the IT department that displays the media access control address and description of every networkadapter on a remote computer with the Internet Protocol address 192.168.1.200.Which of the following C# code samples does this correctly?1. ConnectionOptions co = new ConnectionOptions(@"\\192.168.1.200");ObjectQuery oq = new ObjectQuery("SELECT * FROM Win32_NetworkAdapterConfiguration");ManagementObjectSearcher mos =new ManagementObjectSearcher(co, oq);ManagementObjectCollection moc = mos.Get();foreach (ManagementObject mo in moc)Console.WriteLine(mo["MacAddress"] + ": " + mo["Description"]);2. ManagementScope ms =new ManagementScope(@"\\192.168.1.200\root\cimv2");ObjectQuery oq = new ObjectQuery("SELECT * FROM Win32_NetworkAdapterConfiguration");ManagementObjectSearcher mos =new ManagementObjectSearcher(ms, oq);ManagementObjectCollection moc = mos.Get();foreach (ManagementObject mo in moc)Console.WriteLine(mo["MacAddress"] + ": " + mo["Description"]);

3. ConnectionOptions co =new ConnectionOptions(@"\\192.168.1.200\root\cimv2");ObjectQuery oq = new ObjectQuery("SELECT * FROM Win32_NetworkAdapterConfiguration");ManagementObjectSearcher mos =new ManagementObjectSearcher(co, oq);ManagementObjectCollection moc = mos.Get();foreach (ManagementObject mo in moc)Console.WriteLine(mo["MacAddress"] + ": " + mo["Description"]);4. ManagementScope ms = new ManagementScope(@"\\192.168.1.200");ObjectQuery oq = new ObjectQuery("SELECT * FROM Win32_NetworkAdapterConfiguration");ManagementObjectSearcher mos =

Page 13: Microsoft .NET Framework, Application Development Foundation

new ManagementObjectSearcher(ms, oq);ManagementObjectCollection moc = mos.Get();foreach (ManagementObject mo in moc)Console.WriteLine(mo["MacAddress"] + ": " + mo["Description"]);

Explanation:To query running network adapters on a remote computer, perform the following steps:1. Create a ManagementScope object to define the remote computer. The scope is not simply the computer name, however. Itmust be in the form "\\computername\root\cim2".2. Create an instance of ObjectQuery using a Windows Management Instrumentation (WMI) query. The WMI query must be inthe form "SELECT fields FROM Win32_NetworkAdapterConfiguration".3. Create an instance of ManagementObjectSearcher by providing both the scope and the query.4. Create an instance of ManagementObjectCollection by calling the ManagementObjectSearcher.Get method.You can then iterate through the ManagementObject objects in the ManagementObjectCollection to examine individualnetwork adapters.You can create a ConnectionsOptions object if you want to specify a username and password. However, you cannot use aConnectionsOptions object in place of a ManagementScope object.Objective:Embedding configuration, diagnostic, management, and installation features into a .NET Framework applicationSub Objective(s):Embed management information and events into a .NET Framework application.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 10 - Lesson 3ManagementObjectSearcher ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.management.managementobjectsearcher.aspxObjectQuery ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.management.objectquery.aspxManagementObjectCollection ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.management.managementobjectcollection.aspxWMI .NET OverviewMSDN LibraryLink: http://msdn.microsoft.com/library/ms257340.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 18 (536P_4.2_03)Which of the following C# code samples correctly deserializes the current date and time from an Extensible Markup Language(XML) file?1. FileStream fs = new FileStream("SerializedDate.XML", FileMode.Open);XmlSerializer xs = new XmlSerializer(typeof(DateTime));DateTime t = (DateTime)xs.Deserialize(fs);

2. FileStream fs = new FileStream("SerializedDate.XML", FileMode.Open);XmlSerializer xs = new XmlSerializer(fs);DateTime t = (DateTime)xs.Deserialize();3. FileStream fs = new FileStream("SerializedDate.XML", FileMode.Open);

Page 14: Microsoft .NET Framework, Application Development Foundation

XmlSerializer xs = new XmlSerializer();DateTime t = (DateTime)xs.Deserialize(fs);4. FileStream fs = new FileStream("SerializedDate.XML", FileMode.Open);DateTime t = (DateTime)XmlSerializer.Read(fs);

Explanation:To deserialize an object, first create a Stream, TextReader, or XmlReader object to read the serialized input. Then create anXmlSerializer object (in the System.Xml.Serialization namespace) by passing it the type of object you plan to deserialize.Finally, call the XmlSerializer.Deserialize method to deserialize the object, and cast it to the correct type.No overload for the XmlSerializer constructor takes zero parameters.There is no static XmlSerializer.Read method.The XmlSerializer constructor requires a Type object and cannot accept a FileStream object.Objective:Implementing serialization and input/output functionality in a .NET Framework applicationSub Objective(s):Control the serialization of an object into XML format by using the System.Xml.Serialization namespace.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 5 - Lessons 2 and 3Basic SerializationMSDN LibraryLink: http://msdn.microsoft.com/library/4abbf6k0.aspxXmlSerializer ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.xml.serialization.xmlserializer.aspxIntroducing XML SerializationMSDN LibraryLink: http://msdn.microsoft.com/library/182eeyhh.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 19 (536P_5.5_03)Your IT department has requested your assistance. They have asked you to write a Console application that analyzes theC:\Boot.ini file on a Windows XP system to determine whether it is properly configured. The IT department will deploy your toolwith administrative privileges, and you want to minimize the risk that the application will be abused to perform unauthorizedtasks.Which of the following C# attributes would you use to minimize the security risk by limiting the assembly's privileges so that itcan access only the C:\Boot.ini file?1. [assembly:FileIOPermissionAttribute(SecurityAction.RequestMinimum)]2. [assembly:FileIOPermissionAttribute(SecurityAction.RequestMinimum,Read=@"C:\boot.ini")]3. [assembly:FileIOPermissionAttribute(SecurityAction.PermitOnly,Read=@"C:\boot.ini")]4. [assembly:FileIOPermissionAttribute(SecurityAction.RequestOptional,Read=@"C:\boot.ini")]

Explanation:For declarative security attributes, use SecurityAction.RequestOptional to list only the code access security permissions that

Page 15: Microsoft .NET Framework, Application Development Foundation

your application should have. In addition, you might want to use SecurityAction.RequestMinimum to cause the runtime to throwan exception if the assembly lacks the required permission.SecurityAction.PermitOnly cannot be used in declarative attributes.SecurityAction.RequestMinimum causes the runtime to throw an exception if the runtime lacks the listed permissions.However, it does not cause the runtime to reduce the assembly's permissions.Objective:Improving the security of .NET Framework applications by using the .NET Framework security featuresSub Objective(s):Control permissions for resources by using the System.Security.Permission classes.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 11 - Lesson 3Assemblies Should Declare Minimum SecurityMSDN LibraryLink: http://msdn.microsoft.com/library/ms182325.aspxSecurityAction EnumerationMSDN LibraryLink: http://msdn.microsoft.com/library/system.security.permissions.securityaction.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 20 (536P_6.2_04)Which of the following managed classes corresponds to the unmanaged HANDLE type?1. Double2. Int323. String4. UInt165. IntPtr

Explanation:The IntPtr managed class corresponds to the HANDLE unmanaged type.LPSTR corresponds to the String managed class.The UInt16 managed class corresponds to the WORD unmanaged type.The Int32 managed class corresponds to the INT, LONG, and BOOL unmanaged types.The Double managed class corresponds to the DOUBLE unmanaged type.Objective:Implementing interoperability, reflection, and mailing functionality in a .NET Framework applicationSub Objective(s):Call unmanaged DLL functions within a .NET Framework application, and control the marshalling of data in a .NET Frameworkapplication.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 13 - Lesson 2Platform Invoke Data TypesMSDN LibraryLink: http://msdn.microsoft.com/library/ac7ay120.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 21 (536P_7.1_09)You are creating a Microsoft Windows service.

Page 16: Microsoft .NET Framework, Application Development Foundation

Which of the following security contexts should you specify for the Account property to reduce security risks by running as anonprivileged user while presenting anonymous credentials to network resources?1. NetworkService2. LocalSystem3. LocalService 4. User

Explanation:LocalService runs in the context of an account that acts as a nonprivileged user on the local computer, and it presentsanonymous credentials to any remote server.User causes the system to prompt for a valid username and password when the service is installed, and it runs in the contextof an account specified by a single user on the network.LocalSystem runs in the context of an account that provides extensive local privileges, and it presents the computer'scredentials to any remote server.NetworkService runs in the context of an account that acts as a nonprivileged user on the local computer, and it presents thecomputer's credentials (not a specific user's credentials) to any remote server.Objective:Implementing globalization, drawing, and text manipulation functionality in a .NET Framework applicationSub Objective(s):Format data based on culture information.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 16 - Lesson 1How to: Specify the Security Context for ServicesMSDN LibraryLink: http://msdn.microsoft.com/library/0x72fzyf.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 22 (536P_1.4_08)You are writing an application that analyzes Internet Protocol (IP) subnets and makes recommendations about how to use anaddress space most efficiently. IP addresses are 32-bit values, and you need to be able to analyze individual bits and performboolean arithmetic.Which of the following classes would be most efficient?1. BitArray2. Boolean3. ArrayList4. BitVector32

Explanation:The purpose of the BitVector32 structure is to aid in manipulating bits in a 32-bit integer, and it is perfect for IP addresses.The BitArray class is a resizable collection that can store boolean values. In addition to being resizable, it supports common bit-level operations such as AND, NOT, OR, and XOR (exclusive-or). However, you have more flexibility when working with aBitVector32 structure than a 32-bit BitArray instance.Boolean is a single-bit value. You would need to separately access 32 boolean variables, which would not be efficient.ArrayList does not support boolean math.

Page 17: Microsoft .NET Framework, Application Development Foundation

Objective:Developing applications that use system types and collectionsSub Objective(s):Manage data in a .NET Framework application by using specialized collections.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 4 - Lesson 1BitVector32 StructureMSDN LibraryLink: http://msdn.microsoft.com/library/system.collections.specialized.bitvector32.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 23 (536P_2.2_01)You have written a multithreaded application for.NET Framework version 3.5.What happens if an unhandled exception occurs in a thread you start?1. The runtime provides a backstop for the unhandled exception.2. The exception is forwarded to the main thread. 3. The runtime terminates the application.4. The runtime ignores the exception and continues running the thread.

Explanation:The runtime forwards the exception to the parent thread in.NET Framework version 2.0 and later.In.NET Framework versions 1.0 and 1.1, the runtime provides a backstop for unhandled exceptions in child threads. However,this behavior has changed beginning with.NET Framework version 2.0.Unhandled exceptions often result in terminating the application; however, the parent process does have the opportunity tohandle the exception.The runtime does not ignore exceptions under any circumstances.Objective:Implementing service processes, threading, and application domains in a .NET Framework applicationSub Objective(s):Develop multithreaded .NET applications.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 7 - Lesson 2Exceptions in Managed ThreadsMSDN LibraryLink: http://msdn.microsoft.com/library/ms228965.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 24 (536P_3.5_01)You are in the process of isolating a complicated bug in a Console application that occurs only in rare circumstances. Youwould like to pause execution to examine the values of variables during debugging, but you do not want to pause executionwhen users run release versions of the application.Which method should you call?1. Debugger.Break 2. Console.ReadLine3. Console.Read4. Debug.Assert

Page 18: Microsoft .NET Framework, Application Development Foundation

Explanation:Debugger.Break acts just like a hard-coded breakpoint, except that you can call it programmatically. The Debugger class isonly used in debug releases.Console.Read and Console.ReadLine interrupt processing in both debug and release versions of code.Debug.Assert validates a value and does not stop execution during debugging.Objective:Embedding configuration, diagnostic, management, and installation features into a .NET Framework applicationSub Objective(s):Debug and trace a .NET Framework application by using the System.Diagnostics namespace.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 10 - Lesson 1Debugger.Break MethodMSDN LibraryLink: http://msdn.microsoft.com/library/system.diagnostics.debugger.break.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 25 (536P_4.6_01)Which of the following C# code samples correctly creates a new file named Hello.dat and writes the string "Hello, world!" to it?1. FileStream fs = new FileStream("Hello.dat", FileMode.CreateNew);BinaryWriter bw = new BinaryWriter(fs);bw.BaseStream.Write("Hello, world!");bw.Close();fs.Close();2. FileStream fs = new FileStream("Hello.dat", FileMode.CreateNew);BinaryWriter bw = new BinaryWriter(fs);bw.Write("Hello, world!");bw.Close();fs.Close();

3. FileStream fs = new FileStream("Hello.dat", FileMode.CreateNew);BinaryWriter bw = new BinaryWriter(fs);fs.Write("Hello, world!");bw.Close();fs.Close();4. BinaryWriter bw = new BinaryWriter("Hello.dat", FileMode.CreateNew);bw.Write("Hello, world!");bw.Close();

Explanation:To write to a file with BinaryWriter, first create a FileStream object and use that to create the BinaryWriter object. Then call theBinaryWriter.Write method. Finally, close both the BinaryWriter object and the FileStream object.You can write directly to a FileStream object; however, the FileStream.Write method does not accept a string parameter.You cannot use a BinaryWriter object without creating a FileStream object first.Objective:Implementing serialization and input/output functionality in a .NET Framework applicationSub Objective(s):Manage .NET Framework application data by using Reader and Writer classes.References:

Page 19: Microsoft .NET Framework, Application Development Foundation

MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 2 - Lesson 2How to: Read and Write to a Newly Created Data FileMSDN LibraryLink: http://msdn.microsoft.com/library/36b93480.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 26 (536P_5.6_05)Place the security policy levels in order from highest to lowest.From the list on the right, select valid policy levels. Place your selections in the list on the left in order from highest to lowest.Place your selections in the list on the left by clicking the items in the list on the right and clicking the arrow. You can also usethe Up and Down buttons to rearrange items in the list on the left. You might not need to use all the items from the list on theright.

Explanation:The highest level of security policy is enterprise-wide. Successive lower levels of hierarchy represent further policy restrictions,but they can never grant more permissions than allowed by higher levels. The following policy levels are implemented:1. Enterprise: security policy for all managed code in an enterprise2. Machine: security policy for all managed code that is run on the computer3. User: security policy for all managed code that is run by the user4. Application domain: security policy for all managed code in an applicationThere is no Application policy level.Objective:Improving the security of .NET Framework applications by using the .NET Framework security featuresSub Objective(s):Control code privileges by using System.Security.Policy classes.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 11 - Lesson 1PolicyLevel ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.security.policy.policylevel.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 27 (536P_6.4_03)You are writing an application that needs to transmit e-mail messages through a standard Simple Mail Transfer Protocol(SMTP) server, as well as perform other actions. To ensure that administrators configure the application with the appropriatepermissions, you want to declare the required permission. You do not want to affect the permissions granted to the assembly,however.Which of the following declarations accomplishes this most effectively?1. [assembly:SmtpPermission(SecurityAction.RequestMinimum, Access="Connect")] 2. [assembly:SmtpPermission(SecurityAction.RequestMinimum,Access="ConnectToUnrestrictedPort")]3. [assembly:SmtpPermission(SecurityAction.RequestOptional, Access="Connect")]4. [assembly:SmtpPermission(SecurityAction.RequestOptional,

Page 20: Microsoft .NET Framework, Application Development Foundation

Access="ConnectToUnrestrictedPort")]

Explanation:Use SecurityAction.RequestMinimum to demand specific permissions and to declare them for administrators.SmtpAccess.Connect is the most precise access declaration available.Using SmtpAccess.ConnectToUnrestrictedPort enables the assembly to connect to nonstandard SMTP servers, which isunnecessary in this example. In addition, SecurityAction.RequestOptional causes the runtime to revoke all permissions exceptthose specifically listed. The

Question stated that you did not want to affect the assembly's permissions.Objective:Implementing interoperability, reflection, and mailing functionality in a .NET Framework applicationSub Objective(s):Send electronic mail to a Simple Mail Transfer Protocol (SMTP) server for delivery from a .NET Framework application.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 15 - Lesson 2SmtpPermission ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.net.mail.smtppermission(VS.80).aspxSmtpAccess EnumerationMSDN LibraryLink: http://msdn.microsoft.com/library/system.net.mail.smtpaccess(VS.80).aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 28 (536P_7.1_01)You are writing an English-language client application that must process data files generated by a server application. Theserver application runs at your organization's office in Sweden and was developed locally.How can you change the culture of your C# application to ensure the data file is processed correctly?1. Thread.CurrentThread.CurrentCulture = new CultureInfo("sv-SE"); 2. CultureInfo.CurrentCulture = "sv-SE";3. CultureInfo.CurrentCulture = new CultureInfo("sv-SE");4. Thread.CurrentThread.CurrentCulture.Name = "sv-SE";

Explanation:To modify the culture setting, set the Thread.CurrentThread.CurrentCulture property using a CultureInfo object.CultureInfo.CurrentCulture is read-only.CultureInfo.CurrentCulture is read-only and is of type CultureInfo.Thread.CurrentThread.CurrentCulture.Name is a read-only property.Objective:Implementing globalization, drawing, and text manipulation functionality in a .NET Framework applicationSub Objective(s):Format data based on culture information.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 16 - Lesson 1

Page 21: Microsoft .NET Framework, Application Development Foundation

CultureInfo ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.globalization.cultureinfo.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 29 (536P_1.6_08)Which of the following are events for the System.Windows.Forms.Button class? (Choose three.)1. Resize2. Serializing3. MouseOver4. Click 5. MouseHover 6. Enter

Explanation:Click, Enter, and MouseHover are all valid events for the System.Windows.Forms.Button class.MouseOver, Resize, and Serializing are not events for the Button class.Objective:Developing applications that use system types and collectionsSub Objective(s):Control interactions between .NET Framework application components by using events and delegates.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 1 - Lesson 3Button ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.windows.forms.button.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 30 (536P_2.3_05)Which of the following would you examine to determine whether the currently running assembly has permission to downloadassemblies via Hypertext Transfer Protocol (HTTP)?1. AppDomainSetup.CurrentDomain.DisallowCodeDownload2. AppDomain.CurrentDomain.DisallowCodeDownload3. this.SetupInformation.DisallowCodeDownload4. AppDomain.CurrentDomain.SetupInformation.DisallowCodeDownload

Explanation:To determine whether the currently running assembly has permission to download assemblies via HTTP, examine theAppDomain.CurrentDomain.SetupInformation.DisallowCodeDownload object.Objective:Implementing service processes, threading, and application domains in a .NET Framework applicationSub Objective(s):Create a unit of isolation for common language runtime within a .NET Framework application by using application domains.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 8 - Lesson 2AppDomain ClassMSDN Library

Page 22: Microsoft .NET Framework, Application Development Foundation

Link: http://msdn.microsoft.com/library/system.appdomain.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 31 (536P_3.6_02)As a favor to your IT department, you are writing a Console application that outputs information related to the security of thecurrent computer.Which of the following C# code samples correctly displays running services?1. ObjectQuery oq = new ObjectQuery("SELECT Caption FROM Win32_Service WHERE Started = FALSE");ManagementObjectSearcher mos = new ManagementObjectSearcher(oq);ManagementObjectCollection moc = mos.Get();foreach (ManagementObject mo in moc)Console.WriteLine(mo["Caption"]);2. ObjectQuery oq = new ObjectQuery("SELECT Caption FROM Win32_Service WHERE Started = TRUE");ManagementObjectSearcher mos = new ManagementObjectSearcher(oq);ManagementObjectCollection moc = mos.Query();foreach (ManagementObject mo in moc)Console.WriteLine(mo["Caption"]);3. ObjectQuery oq = new ObjectQuery("SELECT Caption FROM Win32_Service WHERE Started = FALSE");ManagementObjectSearcher mos = new ManagementObjectSearcher(oq);ManagementObjectCollection moc = mos.Query();foreach (ManagementObject mo in moc)Console.WriteLine(mo["Caption"]);4. ObjectQuery oq = new ObjectQuery("SELECT Caption FROM Win32_Service WHERE Started = TRUE");ManagementObjectSearcher mos = new ManagementObjectSearcher(oq);ManagementObjectCollection moc = mos.Get();foreach (ManagementObject mo in moc)Console.WriteLine(mo["Caption"]);

Explanation:To query running services, perform the following steps:1. Create an instance of ObjectQuery using a Windows Management Instrumentation (WMI) query. The WMI query must be inthe form "SELECT fields FROM Win32_Service WHERE criteria". In this case, the criteria must be "WHERE Started = True" toreturn services that have started.2. Create an instance of ManagementObjectSearcher based on the query.3. Next, create an instance of ManagementObjectCollection by calling the ManagementObjectSearcher.Get method.You can then iterate through the ManagementObject objects in the ManagementObjectCollection to examine individualservices.ManagementObjectSearcher.Query is a property used to define the query; it is not a method. You must useManagementObjectSearcher.Get to run a query.Objective:Embedding configuration, diagnostic, management, and installation features into a .NET Framework applicationSub Objective(s):Embed management information and events into a .NET Framework application.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEdition

Page 23: Microsoft .NET Framework, Application Development Foundation

Chapter 10 - Lesson 3ManagementObjectSearcher ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.management.managementobjectsearcher.aspxObjectQuery ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.management.objectquery.aspxManagementObjectCollection ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.management.managementobjectcollection.aspxWMI .NET OverviewMSDN LibraryLink: http://msdn.microsoft.com/library/ms257340.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 32 (536P_4.4_02)You need to create a directory if it does not yet exist.Of the following C# code samples, which most efficiently creates a directory without throwing an exception if it already exists?(If more than one code sample would work correctly, choose the sample that performs the desired task with the fewest lines ofcode.)1. DirectoryInfo di = new DirectoryInfo(@"C:\dir\");di.Create();2. if (!Directory.Exists(@"C:\dir\"))Directory.CreateDirectory(@"C:\dir\");3. DirectoryInfo di = new DirectoryInfo(@"C:\dir\");if (!di.Exists)di.Create();4. Directory.CreateDirectory(@"C:\dir\");

Explanation:Each of these code samples creates a directory without causing the runtime to throw an exception if the directory alreadyexists. The most efficient technique is to call the static Directory.CreateDirectory method.It is unnecessary to test whether a directory already exists before creating it.Objective:Implementing serialization and input/output functionality in a .NET Framework applicationSub Objective(s):Access files and folders by using the File System classes.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 2 - Lesson 1Directory ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.io.directory.aspxDirectoryInfo ClassMSDN LibraryLink: http://msdn.microsoft.com/en-us/library/system.io.directoryinfo.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 33 (536P_5.4_05)You are creating an assembly that needs to store private data to the disk. To protect the private data, you are encrypting itusing asymmetric encryption.

Page 24: Microsoft .NET Framework, Application Development Foundation

From the list on the right, select the tasks that you should perform to create and store a private encryption key. Place yourselections in the list on the left in the order in which the tasks should be performed. Place your selections in the list on the leftby clicking the items in the list on the right and clicking the arrow. You can also use the Up and Down buttons to rearrangeitems in the list on the left. You might not need to use all the items from the list on the right.

Explanation:To store private keys persistently, you must create a CspParameters object, specify the CspParameters.KeyContainerNameproperty, use that CspParameters object to create an RSACryptoServiceProvider object, and then set theRSACryptoServiceProvider.PersistKeyInCsp property to True.You cannot use the blank RSACryptoServiceProvider constructor first and then define the CspParameters object later. Youmust specify the CspParameters object during the RSACryptoServiceProvider construction.You do not need to set the RSACryptoServiceProvider.ExportParameters property to True.Objective:Improving the security of .NET Framework applications by using the .NET Framework security featuresSub Objective(s):Encrypt, decrypt, and hash data by using the System.Security.Cryptography classes.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 12 - Lesson 3How to: Store Asymmetric Keys in a Key ContainerMSDN LibraryLink: http://msdn.microsoft.com/library/tswxhw92.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 34 (536P_6.4_04)Your IT department has asked you to write a simple administrative tool. This tool will run automatically after the Boot.ini file hasbeen modified on a system running Microsoft Windows XP. The tool must send the Boot.ini file as an e-mail attachment to thee-mail address [email protected]. To reduce security risks, you want to grant your assembly the most restrictive permissionspossible.Given the following C# code sample, which of the following security declarations should you use? (Choose all that apply.)MailMessage message = new MailMessage("[email protected]","[email protected]","Modified system file","See the attached file.");Attachment data = new Attachment(@"C:\Boot.ini",MediaTypeNames.Application.Octet);message.Attachments.Add(data);SmtpClient client = new SmtpClient("smtp.contoso.com", 1025);client.Send(message);data.Dispose();1. [assembly: FileIOPermission(SecurityAction.RequestOptional,Read = @"C:\ ")]2. [assembly: SmtpPermission(SecurityAction.RequestOptional,Access = "Connect")]3. [assembly: FileIOPermission(SecurityAction.RequestOptional,

Page 25: Microsoft .NET Framework, Application Development Foundation

Read = @"C:\boot.ini")] 4. [assembly: SmtpPermission(SecurityAction.RequestOptional,Access = "ConnectToUnrestrictedPort")]

Explanation:This assembly requires two permissions: SmtpPermission and FileIOPermission. The most restrictive way that you can specifythe SmtpPermission is to declare the ConnectToUnrestrictedPort access, because the code sample uses a nonstandard portnumber. The most restrictive way that you can specify the FileIOPermission is to specify Read access for the specific file.Specifying the Connect access level for SmtpPermission would not allow the application to run because it does not use thestandard Simple Mail Transfer Protocol port of TCP 25.Specifying Read access to the entire C:\ drive is too general and would grant the assembly unnecessary privileges.Objective:Implementing interoperability, reflection, and mailing functionality in a .NET Framework applicationSub Objective(s):Send electronic mail to a Simple Mail Transfer Protocol (SMTP) server for delivery from a .NET Framework application.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 15 - Lesson 2MailMessage ClassMSDN LibraryLink: http://msdn.microsoft.com/library/8t22a8ww(en-US,VS.80).aspxAssemblies Should Declare Minimum SecurityMSDN LibraryLink: http://msdn.microsoft.com/library/ms182325.aspxSecurityAction EnumerationMSDN LibraryLink: http://msdn.microsoft.com/library/system.security.permissions.securityaction.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 35 (536P_7.1_10)You are creating a Microsoft Windows service.Which of the following security contexts should you specify for the Account property to reduce security risks by running as anonprivileged user while presenting computer credentials to network resources?1. User2. NetworkService 3. LocalService4. LocalSystem

Explanation:NetworkService runs in the context of an account that acts as a nonprivileged user on the local computer, and it presents thecomputer's credentials (not a specific user's credentials) to any remote server.LocalService runs in the context of an account that acts as a nonprivileged user on the local computer, and it presentsanonymous credentials to any remote server.User causes the system to prompt for a valid username and password when the service is installed, and it runs in the contextof an account specified by a single user on the network.

Page 26: Microsoft .NET Framework, Application Development Foundation

LocalSystem runs in the context of an account that provides extensive local privileges, and it presents the computer'scredentials to any remote server.Objective:Implementing globalization, drawing, and text manipulation functionality in a .NET Framework applicationSub Objective(s):Format data based on culture information.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 16 - Lesson 1How to: Specify the Security Context for ServicesMSDN LibraryLink: http://msdn.microsoft.com/library/0x72fzyf.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 36 (536P_1.4_03)You write the following C# console application:NameValueCollection sl = new NameValueCollection();sl.Add("Key", "One.");sl.Add("Key", "Two.");foreach (string s in sl.GetValues("Key"))Console.WriteLine(s);What is the output of this application?1. Two.2. The code fails to compile.3. One.4. One.Two.

Explanation:This code compiles. The NameValueCollection class is a specialized dictionary that allows multiple values to be stored for asingle key. By calling NameValueDictionary.GetValues, you can iterate through every value with a specific key.Objective:Developing applications that use system types and collectionsSub Objective(s):Manage data in a .NET Framework application by using specialized collections.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 4 - Lesson 2NameValueCollection ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.collections.specialized.namevaluecollection.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 37 (536P_2.1_02)Which of the following is a valid reason to create a service?1. Users must be able to run your application without Administrator privileges.2. All users on the computer must be able to run your application.3. Your application must start automatically when a user logs on.4. You need to monitor an aspect of the operating system without a user logging on.

Page 27: Microsoft .NET Framework, Application Development Foundation

Explanation:Services run in the background without requiring a user to log on. Therefore, they are perfect for monitoring the operatingsystem or responding to events.Services are not run directly by users.Services can start automatically when the computer starts. To have an assembly start automatically when a user logs on,simply add a shortcut to the application to the user's Startup group.Objective:Implementing service processes, threading, and application domains in a .NET Framework applicationSub Objective(s):Implement, install, and control a service.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 8 - Lesson 3ServiceController ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.serviceprocess.servicecontroller.aspxIntroduction to Windows Service ApplicationsMSDN LibraryLink: http://msdn.microsoft.com/library/d56de412.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 38 (536P_3.3_03)Which of the following C# code samples successfully writes the entire contents of the Application log to the console?1. EventLog el = new EventLog();el.Log = "Application";foreach (EventLogEntry ele in el.Entries)Console.WriteLine(ele.Source + ":" + ele.Message);

2. EventLog el = new EventLog();foreach (EventLog ele in el.Entries)Console.WriteLine(ele.Source + ":" + ele.Message);3. EventLog el = new EventLog();foreach (EventLogEntry ele in el.Entries)Console.WriteLine(ele.Source + ":" + ele.Message);4. EventLog el = new EventLog();el.Log = "Application";foreach (EventLog ele in el.Entries)Console.WriteLine(ele.Source + ":" + ele.Message);

Explanation:To read an entire log file, create an instance of the EventLog class, specify the EventLog.Log property, and then iteratethrough EventLog.Entries. EventLog.Entries is an EventLogEntryCollection property containing EventLogEntry objects.Objective:Embedding configuration, diagnostic, management, and installation features into a .NET Framework applicationSub Objective(s):Manage an event log by using the System.Diagnostics namespace.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, Second

Page 28: Microsoft .NET Framework, Application Development Foundation

EditionChapter 10 - Lesson 1EventLog ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.diagnostics.eventlog.aspxLogging Application, Server, and Security EventsMSDN LibraryLink: http://msdn.microsoft.com/library/e6t4tk09.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 39 (536P_4.6_02)You need to write text to a file.Which of the following C# code demonstrates the most efficient way to use the TextWriter class?1. FileStream fs = new FileStream("Hello.dat", FileMode.Create);TextWriter tw = new StreamWriter(fs);tw.Write("Hello, world!");tw.Close();fs.Close();

2. TextWriter tw = new TextWriter("Hello.dat");tw.Write("Hello, world!");tw.Close();3. TextWriter tw = new StreamWriter("Hello.dat");tw.Write("Hello, world!");tw.Close();4. TextWriter tw = new FileStream("Hello.dat", FileMode.Create);tw.Write("Hello, world!");tw.Close();

Explanation:The TextWriter class does not have a constructor. Instead, you should create it using the StreamWriter constructor. To createa StreamWriter object, you must use an existing Stream object, such as an instance of FileStream.Objective:Implementing serialization and input/output functionality in a .NET Framework applicationSub Objective(s):Manage .NET Framework application data by using Reader and Writer classes.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 2 - Lesson 2TextWriter ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.io.textwriter.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 40 (536P_5.1_05)Which of the following If statements correctly identifies whether the current assembly has permission to read the C:\Boot.inifile?1. if (SecurityManager.CheckExecutionRights(new FileIOPermission(FileIOPermissionAccess.Read, @"C:\boot.ini")))2. if (SecurityManager.IsGranted(new FileIOPermission(

Page 29: Microsoft .NET Framework, Application Development Foundation

FileIOPermissionAccess.Read, @"C:\boot.ini")))

3. if (SecurityManager.IsGranted(FileIOPermissionAccess.Read, @"C:\boot.ini"))4. if (SecurityManager.CheckExecutionRights(FileIOPermissionAccess.Read, @"C:\boot.ini"))

Explanation:Use SecurityManager.IsGranted to determine imperatively whether the current process has a specific permission.You must provide a Permission object to SecurityManager.IsGranted. You cannot provide a FileIOPermissionAccessenumeration.SecurityManager.CheckExecutionRights only determines whether the process must haveSystem.Security.Permissions.SecurityPermissionFlag.Execution to execute.Objective:Improving the security of .NET Framework applications by using the .NET Framework security featuresSub Objective(s):Implement code access security to improve the security of a .NET Framework application.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 11 - Lesson 3SecurityManager ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.security.securitymanager.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 41 (536P_6.3_04)You are using reflection to load and run an assembly. You need to respond to an event initiated within the loaded assembly.From the list on the right, select the tasks that you should perform to respond to an event by using reflection. Place yourselections in the list on the left in the order in which the tasks should be performed. Place your selections in the list on the leftby clicking the items in the list on the right and clicking the arrow. You can also use the Up and Down buttons to rearrangeitems in the list on the left. You might not need to use all the items from the list on the right.

Explanation:When you use reflection to load and run assemblies, you cannot use language features such as the C# += operator or theVisual Basic AddHandler keyword to hook up events. Instead, you must get all the necessary types through reflection.Objective:Implementing interoperability, reflection, and mailing functionality in a .NET Framework applicationSub Objective(s):Implement reflection functionality in a .NET Framework application, and create metadata, Microsoft intermediate language(MSIL), and a PE file by using the System.Reflection.Emit namespace.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 14 - Lesson 1How to: Hook Up a Delegate Using Reflection

Page 30: Microsoft .NET Framework, Application Development Foundation

MSDN LibraryLink: http://msdn.microsoft.com/library/ms228976.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 42 (536P_7.3_05)You are writing a method that accepts dates as a string in mm/dd/yyyy format and returns the same date in yyyy-mm-ddformat.Which of the following C# methods accomplishes this?1. static string ReformatDate(string s){Match m = Regex.Match(s,@"\b(?<month>\d{1,2})/(?<day>\d{1,2})/(?<year>\d{2,4})\b");return m.Groups["year"] + "-" +m.Groups["month"] + "-" + m.Groups["day"];}

2. static string ReformatDate(string s){Match m = Regex.Match(s,@"\b(<month>\d{1,2})/(<day>\d{1,2})/(<year>\d{2,4})\b");return m.Groups["year"] + "-" +m.Groups["month"] + "-" + m.Groups["day"];}3. static string ReformatDate(string s){Match m = Regex.Match(s,@"\b(<month>\d{1,2})/(<day>\d{1,2})/(<year>\d{2,4})\b");return m.Groups[year] + "-" +m.Groups[month] + "-" + m.Groups[day];}4. static string ReformatDate(string s){Match m = Regex.Match(s,@"\b(?<month>\d{1,2})/(?<day>\d{1,2})/(?<year>\d{2,4})\b");return m.Groups[year] + "-" +m.Groups[month] + "-" + m.Groups[day];}

Explanation:To extract information from a string, create a regular expression and surround the matched text with parentheses. In the caseof a date number, you must match three groups of numbers, each separated by a slash. Months and days are two digits each,and the year can be one to four digits. Compare the date to the regular expression using Regex.Match. In this code sample,named groups are used. The year is placed in the "year" named group, the month in the "month" named group, and the day inthe "day" named group. You can access each group from the Match.Groups collection using the group name, which must be inthe form of a string with quotes.Objective:Implementing globalization, drawing, and text manipulation functionality in a .NET Framework applicationSub Objective(s):Enhance the text handling capabilities of a .NET Framework application, and search, modify, and control text within a .NETFramework application by using regular expressions.References:

Page 31: Microsoft .NET Framework, Application Development Foundation

MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 3 - Lesson 1Regular Expression ClassesMSDN LibraryLink: http://msdn.microsoft.com/library/30wbz966.aspxRegex ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.text.regularexpressions.regex.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 43 (536P_1.5_04)Given the following C# code sample, which interface must the custom class MyClass implement?MyClass a; bool b;a = 42;// Convert using ToBoolean.b = Convert.ToBoolean(a);Console.WriteLine("a = {0}, b = {1}", a.ToString(), b.ToString());1. IConvertible 2. IComparable3. ICloneable4. IDisposable5. IEquatable6. IFormattable7. INullableValue

Explanation:Use the IConvertible interface to enable a custom class to be converted to other types.Implementing the other interfaces does not allow a class to be converted.Objective:Developing applications that use system types and collectionsSub Objective(s):Implement .NET Framework interfaces to cause components to comply with standard contracts.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 1 - Lesson 4IConvertible InterfaceMSDN LibraryLink: http://msdn.microsoft.com/library/system.iconvertible.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 44 (536P_2.2_06)You are writing an application that needs to perform processing that will run for several hours. However, you need theapplication to remain responsive to the user during that time, so you are using multiple threads.Which of the following C# code samples starts the thread so as to minimize the impact on the performance of otherapplications?1. ThreadStart myThreadDelegate = new ThreadStart(ThreadWork.DoWork, ThreadPriority.Lowest);Thread myThread = new Thread(myThreadDelegate);myThread.Start();2. ThreadStart myThreadDelegate = new ThreadStart(ThreadWork.DoWork);Thread myThread = new Thread(myThreadDelegate);

Page 32: Microsoft .NET Framework, Application Development Foundation

myThread.Priority = ThreadPriority.Lowest;myThread.Start();

3. ThreadStart myThreadDelegate = new ThreadStart(ThreadWork.DoWork);Thread myThread = new Thread(myThreadDelegate, ThreadPriority.Lowest);myThread.Start();4. ThreadStart myThreadDelegate = new ThreadStart(ThreadWork.DoWork);Thread myThread = new Thread(myThreadDelegate);myThread.StartLowPriority();

Explanation:Set the Thread.Priority property to control a thread's processing priority.The Thread.StartLowPriority method does not exist.You cannot pass a priority level to the Thread constructor.You cannot pass a priority level to the ThreadStart constructor.Objective:Implementing service processes, threading, and application domains in a .NET Framework applicationSub Objective(s):Develop multithreaded .NET applications.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 7 - Lesson 1Scheduling ThreadsMSDN LibraryLink: http://msdn.microsoft.com/library/2k34xtf3.aspxTS: Microsoft .NET Framework, Application Development Foundation

Question Number (ID) : 45 (536P_3.1_03)Which class would you use to access programmatically the connection strings stored in the following configuration file? (Theconnection strings have been formatted to fit on multiple lines.)<?xml version="1.0" encoding="utf-8" ?><configuration><connectionStrings><clear/><add name="AdventureWorksString"providerName="System.Data.SqlClient"connectionString="Data Source=localhost;Initial Catalog=AdventureWorks; Integrated Security=true"/><add name="MarsEnabledSqlServer2005String"providerName="System.Data.SqlClient"connectionString="Server=Aron1;Database=pubs;Trusted_Connection=True;MultipleActiveResultSets=true" /><add name="OdbcConnectionString"providerName="System.Data.Odbc"connectionString="Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\adatabase.mdb;Uid=Admin;Pwd=R3m3emberToUseStrongPasswords;"/></connectionStrings></configuration>1. ConfigurationSettings.ConnectionStrings2. ConfigurationSection.ConnectionStrings3. ConfigurationProperty.ConnectionStrings4. ConfigurationManager.ConnectionStrings

Explanation:

Page 33: Microsoft .NET Framework, Application Development Foundation

Use ConfigurationManager.ConnectionStrings to access database connection strings.ConfigurationSettings is obsolete.ConfigurationSection does not have a ConnectionStrings property.ConfigurationProperty does not have a ConnectionStrings property.Objective:Embedding configuration, diagnostic, management, and installation features into a .NET Framework applicationSub Objective(s):Embed configuration management functionality into a .NET Framework application.References:MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework - Application Development Foundation, SecondEditionChapter 9 - Lesson 1ConfigurationManager.ConnectionStrings PropertyMSDN LibraryLink: http://msdn.microsoft.com/library/system.configuration.configurationmanager.connectionstrings.aspx