70-483: Exam Questions

Description

Certificate 70-483: Programming in C# (Exam Questions) Quiz on 70-483: Exam Questions, created by Paige Gentry on 15/06/2016.
Paige Gentry
Quiz by Paige Gentry, updated more than 1 year ago
Paige Gentry
Created by Paige Gentry almost 8 years ago
268
1

Resource summary

Question 1

Question
You are developing an application. The application calls a method that returns an array of integers named employeeIds. You define an integer varaiable named employeeIdToRemove and assigna a value to it. You declare an array named filteredEmployeeIds. You have the following requirements: - Remove duplicate integers from the employeeIds array - Sort the array in order from the highest to the lowest value - Remove the integer value stored in the employeeIdToRemove variable from the employeeIds array You need to create a LINQ query to meet the requirements. Which should you do?
Answer
  • A. int[] filteredEmployeeIds = employeeIds.Where(v => v != employeeIdToRemove).OrderBy(x => x).ToArray();
  • B. int[] filteredEmployeeIds = employeeIds.Where(v => v != employeeIdToRemove).OrderByDescending(x => x).ToArray();
  • C. int[] filteredEmployeeIds = employeeIds.Distinct().Where(v => v != employeeIdToRemove).OrderByDescending(x => x).ToArray();
  • D. int[] filteredEmployeeIds = employeeIds.Distinct().OrderByDescending(x => x).ToArray();

Question 2

Question
You are developing an application that includes a class named Order. The application will store a collection of Order objects. The collection must meet the following requirements: - Use strongly typed members - Process Order objects in first-in-first-out order - Store values for each Order object - User zero-based indices Which Collection would you use?
Answer
  • Queue<T>
  • SortedList
  • LinkedList<T>
  • HashTable
  • Array<T>

Question 3

Question
You are developing an application that includes the following code segment. 01 Class Animal { 02 public string Color { get; set;} 03 public string Name { get; set; } 04 } 05 06 private static IEnumerable<Animal> GetAnimals(string sqlConnectionString) { 07 var animals = new List<Animal>(); 08 SqlConnection sqlConnection = new SqlConnection(sqlConnectionString); 09 10 using (sqlConnection) { 11 SqlCommand sqlCommand = new SqlCommand("Select Name, ColorName FROM Animcals", sqlConnection); 12 <MISSING LINE> 13 14 using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader()) { 15 <MISSING LINE> { 16 var animal = new Animal(); 17 animal.Name = (string)sqlDataReader("Name"); 18 animal.Color = (string)sqlDataReader("ColorName"); 19 animals.Add(animal); 20 } 21 } 22 } 23 return customers; 24 } The GetAnimals() method must meed the following requirements: - Connect to a Microsoft SQL Server database - Create Animal objects and populate them with data from the database - Return a sequence of populated Animal objects Which two action should you perform to meet the requirements?
Answer
  • A. At Line 15 insert: while ( sqlDataReader.NextResult() )
  • B. At Line 12 insert: sqlConnection.BeginTransaction();
  • C. At Line 12 insert: sqlConnection.Open()
  • D. At Line 15 insert: while ( sqlDataReader.Read() )
  • E. At Line 15 insert: while ( sqlDataReader.GetValues() )

Question 4

Question
You are developing a custom collection named LoanCollection for a class named Loan class. You need to ensure that you can process each Loan object in the LoanCollection by using a foreach loop. How should you complete the relevant code? public class Loan Collection [blank_start]: IEnumerable[blank_end] { ....private readonly Loan[] _loanCollection; ....public LoanCollection( Loan[] loanArray) { ........_loanCollection = new Loan[loanArray.Length]; ........for(int i = 0; i < loanArray.Length; i++) { ............_loanCollection[i] = loanArray[i]; ........} ....} ....[blank_start]public IEnumerator GetEnumerator() {[blank_end] ........[blank_start]return _loanCollection.GetEnumerator();[blank_end] ....} }
Answer
  • : IEnumerable
  • : IComparable
  • : IDisposable
  • public IEnumerator GetEnumerator() {
  • public int CompareTo (object obj)
  • public void Dispose()
  • return _loanCollection.GetEnumerator();
  • _loanCollection[0].Amount++;
  • return obj==null? :_loanCollection.Lengt

Question 5

Question
You are developing an application that uses the Microsoft ADO.NET Entity Framework to retrieve order information from a Microsoft SQL Server database. The application must meet the following requirements: - Return only orders that have an OrderDate value other than null - Return only orders that were placed in the year specified in the OrderDate property or in a later year 01 public DateTime? OrderDate; 02 03 IQueryable<Order> LookupOrdersForYear (int year) { 04 using ( var context = new NorthwindEntities() ) { 05 var orders = from order in context.Orders 06 <MISSING LINE> 07 select order; 08 09 return orders.ToList().AsQueryable(); 10 } 11 } What code segment should you insert at line 06 to ensure the requirements are met?
Answer
  • A. Where order.OrderDate.Value != null && order.OrderDate.Value.Year >= year
  • B. Where order.OrderDate.Value == null && order.OrderDate.Value.Year == year
  • C. Where order.OrderDate.HasValue && order.OrderDate.Value.Year == year
  • D. Where order.OrderDate.Value.Year == year

Question 6

Question
You are developing an application by using C#. The application includes an array of decimal values named loanAmounts. You are developing a LINQ query to return the values from the array. The query must return decimal values that are evenly divisible by two. The values must be sorted from the lowest value to the highest value. How should you complete the code to ensure the query correctly returns the decimal values? decimal[] loanAmounts = { 303m, 10000m, 12353m, 503.13m, 409m, 32m, 500m }; IEnumerable<decimal> loanQuery = [blank_start]from[blank_end] amount in loanAmounts [blank_start]where[blank_end] amount % 2 == 0 [blank_start]orderby[blank_end] amount [blank_start]ascending[blank_end] [blank_start]select[blank_end] amount;
Answer
  • from
  • join
  • where
  • group
  • orderby
  • descending
  • select
  • ascending

Question 7

Question
You are developing an application. The application includes a method named ReadFile that reads data from a file. The ReadFile() method must meet the following requirements: - It must not make changes to the data file. - It must allow other processes to access the data file. - It must not throw an exception if the application attempts to open a data file that does not exist. Which code segment should you use to implement to ReadFile() method?
Answer
  • A. var fs = File.ReadAllBytes(Filename);
  • B. var fs = File.Open(Filename, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite);
  • C. var fs = File.ReadAllLines(Filename);
  • D. var fs = File.Open(Filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
  • E. var fs = File.Open(Filename, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Write);

Question 8

Question
An application receives JSON in the following format: { "FirstName" : "David", "LastName" : "Jones", "Values" : [0, 1, 2] } The application includes the following code segment: 01 public class Name { 02 public int[] Values { get; set; } 03 public string FirstName { get; set; } 04 public string LastName { get; set; } 05 } 06 07 public static Name ConvertToName(string json) { 08 var ser = new JavaScriptSerializer(); 09 <MISSING LINE> 10 } Which code segment should be inserted at line 09 to ensure that ConvertToName() method returns the JSON input string as a Name object?
Answer
  • A. Return ser.ConvertToType<Name> ( json );
  • B. Return ser.DeserializeObject( json );
  • C. Return ser.Deserialize<Name> ( json );
  • D. Return (Name)ser.Serialize( json );

Question 9

Question
An application serializes and deserializes XML from streams. The XML streams are in the following format: <Name xmlns = "http://www.contoso.com/2012/06"> <LastName> Jones </LastName> <FirstName> David </FirstName> </Name> The application reads the XML streams by using a DataContractSerializer object that is declared by the following code segment: var ser = new DataContractSerializer(typeof(Name)); How should you complete the code to ensure the application preserves the emement ordering as provided in the XML stream? [blank_start][DataContract ( Namespace = "xmlns")][blank_end] class Name { ......[blank_start][DataMember ( Order = 10 )][blank_end] ......public string FirstName { get; set; } ......[blank_start][DataMember][blank_end] ......public string LastName { get; set; } }
Answer
  • [DataContract ( Namespace = "xmlns")]
  • [DataContract ( Name="xmlns", Order=10)]
  • [DataContract ( Name = "xmlns")]
  • [DataContract]
  • [DataMember ( Name = "xmlns")]
  • [DataMember ( Order = 10 )]
  • [DataMember]

Question 10

Question
You are developing an application. The application converts a Location object to a string by using a method named WriteObject. The WriteObject() method accepts two parameters, a Location object and an XmlObjectSerializer object. 01 public enum Compass { 02 North, 03 South, 04 East, 05 West 06 } 07 08 [DataContract] 09 public class Location { 10 [DataMember] 11 public string Label { get; set; } 12 13 [DataMember] 14 public Compass Direction { get; set; } 15 } 16 17 void DoWork() { 18 var location - new Location { Label = "test", Direction = Compass.West }; 19 Console.WriteLine( 20 WriteObject ( Location, <MISSING> )); Which code segment should you insert to serialize the Location object as a JSON object?
Answer
  • A. New DataContractSerializer( typeof ( Location ) )
  • B. New XmlSerializer ( typeof ( Location ) )
  • C. New NetDataContractSerializer()
  • D. New DataContractJsonSerializer ( typeof (Location ) )

Question 11

Question
An application includes a class named Person. The Person class includes a method named GetData. You need to ensure that the GetData() method can be used only by the Person class or a class derived from the Person class. Which access modifier should you use for the GetData() method?
Answer
  • A. Internal
  • B. Protected
  • C. Private
  • D. Protected Internal
  • E. Public

Question 12

Question
01 public interface IDataContainer { 02 string Data { get; set; } 03 } 04 05 void DoWork (object obj) { 06 <MISSING LINE> 07 08 if(dataContainer != null) 09 Console.WriteLine(dataContainer.Data); The DoWork() method must not throw any exceptions when converting the obj object to the IDataContainer interface or when accessing the Data property. What code segment should be inserted to meet the requirements?
Answer
  • A. var dataContainer = ( IDataContainer ) obj;
  • B. dynamic dataContainer = obj;
  • C. var dataContainer = obj is IDataContainer;
  • D. var dataContainer = obj as IDataContainer;

Question 13

Question
You are creating an application that manages information about zoo animals. The application includes a class named Animal and a method named Save. The Save() method must be strongly typed. It must allow only types inherited from the Animal class that uses a constructor that accepts no parameters. Which code segment should you use to implement the Save() method?
Answer
  • A. public static void Save<T> (T target) where T : new( ), Animal {...}
  • B. public static void Save<T> (T target) where T : Animal {...}
  • C. public static void Save<T> (T target) where T : Animal, new( ) {...}
  • D. public static void Save (Animal target) {...}

Question 14

Question
You are developing a class named ExtensionMethods. You need to ensure that the ExtensionMethods class implements the IsUrl() method on string objects. How should you complete the relevant code? [blank_start]public static class ExtensionMethods[blank_end] { .......public static bool IsUrl( [blank_start]this String str[blank_end] ) { ..............var regex = new Regex("Regex expressions" + "More regex expressions" ); ..............return regex.IsMatch(str); .......}
Answer
  • public static class ExtensionMethods
  • public class ExtensionMethods
  • protected static class ExtensionMethods
  • this String str
  • String str

Question 15

Question
You are developing an application. The application includes classes named Employee and Person and an interface named IPerson. The Employee class must meet the following requirements: - It must either inherit from the Person class or implement the IPerson interface. - It must be inheritable by other classes in the application. Which two code segments can you use to meet the requirements?
Answer
  • A. sealed class Employee : Person {...}
  • B. abstract class Employee : Person {...}
  • C. sealed class Employee : IPerson {...}
  • D. abstract class Employee : IPerson {...}

Question 16

Question
You are developing an application that will convert data into multiple output formats. The application includes the following code: 01 public class TabDelimitedFormatter : IOutputFormatter<string> { 02 readonly Func<int, char> suffix = col => col % 2 == 0 ? '\n' : '\t'; 03 04 public string GetOutput(IEnumerator<string> iterator, int recordSize) { 05 <MISSING LINE> 06 } 07 } You are developing a code segment that will produce tab-delimited output. All output routines implement the following interface: public interface IOutputFormatter<T> { string GetOutput(IEnumerator<T> iterator, int recordSize); } Which code segment should you insert at line 04 to minimize the completion time of the GetOutput() method
Answer
  • A. string output = null; for (int i = 1; iterator.MoveNext(); i++){ output = string.Concat(output, iterator.Current, suffix(i)); } return output;
  • B. var output = new StringBuilder(); for (int i = 1; iterator.MoveNext(); i++){ output.Append(iterator.Current); output.Append(suffix(i)); } return output.ToString();
  • C. string output = null; for (int i = 1; iterator.MoveNext(); i++){ output = output + iterator.Current + suffix(i); } return output;
  • D. string output = null; for (int i = 1; iterator.MoveNext(); i++){ output += output + iterator.Current + suffix(i); } return output;

Question 17

Question
You are developing an application by using C#. The application includes an object that performs a long running process. You need to ensure that the garbage collector does not release the object’s resources until the process completes. Which garbage collector method should you use?
Answer
  • A. ReRegisterForFinalize()
  • B. SuppressFinalize()
  • C. Collect()
  • D. WaitForFullGCApproach()

Question 18

Question
You are creating a class named Employee. The class exposes a string property named EmployeeType. The following code segment defines the Employee class. 01 public class Employee { 02 internal string EmployeeType { 03 get; 04 set; 05 } 06 } The EmployeeType property value must be accessed and modified only by code within the Employee class or within a class derived from the Employee class. Which two actions should you perform to ensure the implementation of the EmployeeType property meets the requirements?
Answer
  • A. Replace line 03 with: protected get;
  • B. Replace line 04 with: private set;
  • C. Replace line 02 with: public string EmployeeType
  • D. Replace line 03 with: private get;
  • E. Replace line 02 with: protected string EmployeeType
  • F. Replace line 04 with: protected set;

Question 19

Question
You are implementing a method named Calculate that performs conversions between value types and reference types. The following code segment implements the method. 01 public static void Calculate(float amount) { 02 object amountRef = amount; 03 <MISSING LINE> 04 Console.WriteLine(balance); 05 } Which code segment should you insert at line 03 to ensure the application does not throw exceptions on invalid conversions?
Answer
  • A. int balance = (int) (float)amountRef;
  • B. int balance = (int)amountRef;
  • C. int balance = amountRef;
  • D. int balance = (int) (double)AmountRef;

Question 20

Question
You are creating a console application by using C#. You need to access the application assembly. Which code segment should you use?
Answer
  • A. Assembly.GetAssembly(this);
  • B. this.GetType();
  • C. Assembly.Load();
  • D. Assembly.GetExecutingAssembly();

Question 21

Question
You are implementing a library method that accepts a character parameter and returns a string. If the lookup succeeds, the method must return the corresponding string value. If the lookup fails, the method must return the value “invalid choice.” You need to implement the lookup algorithm. How should you complete the relevant code? public string GetResponse(char letter) { ___string response; ___[blank_start]switch[blank_end] (letter) { ______[blank_start]case[blank_end] 'a': _________response = "animal"; _________break; ______[blank_start]case[blank_end] 'm': _________response = "mineral"; _________break; ______[blank_start]default[blank_end]: _________response = "invalid choice"; _________break; ___} ___return response; }
Answer
  • switch
  • case
  • if
  • case
  • default
  • else
  • if
  • case
  • default
  • else
  • if
  • case
  • default
  • else
  • if

Question 22

Question
You use the Task.Run() method to launch a long-running data processing operation. The data processing operation often fails in times of heavy network congestion. If the data processing operation fails, a second operation must clean up any results of the first operation. You need to ensure that the second operation is invoked only if the data processing operation throws an unhandled exception. What should you do?
Answer
  • A. Create a TaskCompletionSource<T> object and call the TrySetException() method of the object.
  • B. Create a task by calling the Task.ContinueWith() method.
  • C. Examine the Task.Status property immediately after the call to the Task.Run() method.
  • D. Create a task inside the existing Task.Run() method by using the AttachedToParent option.

Question 23

Question
You are modifying an application that processes leases. The following code defines the Lease class. Leases are restricted to a maximum term of 5 years. The application must send a notification message if a lease request exceeds 5 years. 01 public class Lease { 02 <MISSING CODE> 03 private int _term; 04 private const int MaximumTerm = 5; 05 private const decimal Rate = 0.034m; 06 07 public int Term { 08 get { 09 return _term; 10 } 11 set { 12 if(value <= MaximumTerm) { 13 _term = value; 14 } 15 else { 16 <MISSING CODE> 17 } 18 } 19 } 20 } 21 22 public delegate void MaximumTermReachedHandler (object source, EventArgs e); Which two actions should you perform to implement the notification mechanism?
Answer
  • A. Insert at 02: public event MaximumTermReachedHandler OnMaximumTermReached;
  • B. Insert at 16: if ( OnMaximumTermReached != null) OnMaximumTermReached (this, new EventArgs() );
  • C. insert at 16: value = MaximimTerm;
  • D. Insert at 02: public string MaximumTermReachedEvent { get; set; }
  • E. Insert at 02: private string MaximumTermReachedEvent;
  • F. Insert at 16: value = 4

Question 24

Question
You are developing an application that uses structured exception handling. The application includes a class named ExceptionLogger. The ExceptionLogger class implements a method named LogException by using the following code segment: - public static void LogException(Exception ex) You have the following requirements: - Log all exceptions by using the LogException() method of the ExceptionLogger class. - Rethrow the original exception, including the entire exception stack. Which code segment should you use to meed the requirements?
Answer
  • A. catch (Exception ex) { ExceptionLogger.LogException(ex); throw; }
  • B. catch (Exception ex) { ExceptionLogger.LogException(ex); throw ex; }
  • C. catch { ExceptionLogger.LogException(new Exception()); throw; }
  • D. catch { var ex = new Exception(); throw; }

Question 25

Question
You are developing an application that includes a class named UserTracker. The application includes the following code segment. 01 public delegate void AddUserCallback(int i); 02 03 public class userTracker { 04 List<User> users = new List<User>(); 05 public void AddUser(string name, AddUserCallback callback) { 06 users.Add(new User(name)); 07 callback(users.Count); 08 } 09 } 10 <MISSING CODE> 11 12 public class Runner { 13 <MISSING CODE> 14 UserTracker tracker = new UserTracker(); 15 16 public void Add(string name) { 17 <MISSING CODE> 18 } 19 } What should you do to add a user to the UserTracker instance?
Answer
  • A. Insert at 13: private static void PrintUserCount(int i) {...} Insert at 17: AddUserCallback callback = PrintUserCount;
  • B. Insert at 10: delegate void AddUserDelegate(UserTracker userTracker); Insert at 17: AddUserDelegate addDelegate = (userTracker) => {...}; addDelegate(tracker);
  • C. Insert at 10: delegate void AddUserDelegate(string name, AddUserCallback callback); Insert at 17: AddUserDelegate adder = (i, callback) => {...};
  • D. Insert at 17: tracker.AddUser(name, delegate(int i) {...}; )

Question 26

Question
You develop an application that displays information from log files when errors occur. The application will prompt the user to create an error report that sends details about the error and the session to the administrator. When a user opens a log file by using the application, the application throws an exception and closes. The application must preserve the original stack trace information when an exception occurs during this process. How should you complete the relevant code to implement the method that reads the log files? using ([blank_start]StreamReader sr = new StreamReader[blank_end]("log.txt")) { ______try { ____________string line; ____________while((line = sr.ReadLine()) != null) __________________Console.WriteLine(line); ______} ______catch(FileNotFoundException e){ ____________Console.Write(e.ToString()); ____________[blank_start]throw;[blank_end] ______} }
Answer
  • StreamReader sr = new StreamReader
  • StringReader sr = new StringReader
  • throw;
  • throw new FileNotFoundException();

Question 27

Question
You are developing an application that includes a class named Kiosk. The Kiosk class includes a static property named Catalog. The Kiosk class is defined by the following code segment. 01_____public class Kiosk { 02__________static Catalog _catalog = null; 03__________static object _lock = new object(); 04 05__________public static Catalog Catalog { 06_______________get { 07____________________[blank_start]if(_catalog != null) _catalog = new[blank_end] Catalog(); 08____________________[blank_start]if(_catalog != null)[blank_end] 09_________________________[blank_start]lock(_lock);[blank_end] 10____________________return _catalog; 11_______________} 12__________} 13_____} You have the following requirements: - Initialize the _catalog field to a Catalog instance. - Initialize the _catalog field only once. - Ensure that the application code acquires a lock only when the _catalog object must be instantiated. Which three code segments should you insert in sequence at line 07 to meet the requirements?
Answer
  • if(_catalog != null)
  • if(_catalog == null)
  • lock(_lock);
  • if(_catalog != null) _catalog = new
  • if(_catalog == null) _catalog = new

Question 28

Question
You are developing an application that will include a method named GetData. The GetData() method will retrieve several lines of data from a web service by using a System.IO.StreamReader object. You have the following requirements: - The GetData() method must return a string value that contains the first line of the response from the web service. - The application must remain responsive while the GetData() method runs. You need to implement the GetData() method. How should you complete the relevant code to implement to GetDate() method? private [blank_start]async[blank_end] void GetData(WebResponse response) { _____var streamReader = new StreamReader(response.GetREsponseStream()); _____urlText.Text = [blank_start]await[blank_end] streamReader.[blank_start]ReadLineAsync();[blank_end] }
Answer
  • async
  • ToString();
  • await
  • ReadToEnd();
  • ReadLineAsync();
  • ReadLine();
  • ReadToEndAsync();

Question 29

Question
You are adding a public method named UpdateScore to a public class named ScoreCard. The code region that updates the score field must meet the following requirements: - It must be accessed by only one thread at a time. - It must not be vulnerable to a deadlock situation. What should you do to implement the UpdateScore() method?
Answer
  • A. Place the code region inside the following lock statement: lock (this) {...}
  • B. Add a private method named lockObject to the ScoreCard class. Place the code region inside the following lock statement: lock (lockObject) {...}
  • C. Apply the following attribute to the UpdateScore() method signature: [MethodImpl(methodImplOptions.Synchonized]
  • D. Add a public static object named lockObject to the ScoreCard class. Place the code region inside the following lock statement: lock (typeof(ScoreCard)) {...}

Question 30

Question
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: public class AdventureWorksException : System.Exception {...} public class AdventureWorksDbException : AdventureWorksException {...} public class AdventureWorksValidationException : p AdventureWorksException {...} The application includes a function named DoWork that throws .NET Framework exceptions and custom exceptions.The application contains only the following logging methods: static void Log (Exception ex) {...} static void Log (AdventureWorksException ex) {...} static void Log (AdventureWorksValidationException ex) {...} The application must meet the following requirements: - When AdventureWorksValidationException exceptions are caught, log the information by using the static void Log (AdventureWorksValidationException ex) method. - When AdventureWorksDbException or other AdventureWorksException exceptions are caught, log the information by using the static void I oq( AdventureWorksException ex) method. How should you complete the relevant code to meet the requirements? try{ _____DoWork(); } catch ([blank_start]AdventureWorksValidationException ex[blank_end]){ _____Log(ex); } catch ([blank_start]AdventureWorksException ex[blank_end]){ _____Log(ex); } catch ([blank_start]Exception[blank_end] ex){ _____Log(ex); }
Answer
  • AdventureWorksValidationException ex
  • ContosoDbException ex
  • AdventureWorksException ex
  • Exception

Question 31

Question
You are developing a C# application that has a requirement to validate some string input data by using the Regex class. The application includes a method named ContainsHyperlink. The ContainsHyperlink() method will verify the presence of a URI and surrounding markup. The following code segment defines the ContainsHyperlink() method. 01 bool ContainsHyperlink(string input) { 02 string regexPattern = "href\\s*?:1"; 03 <MISSING CODE> 04 return evaluator.IsMatch(inputData); 05 } The expression patterns used for each validation function are constant. Which code segment should you insert at line 04 to ensure that the expression syntax is evaluated only once when the Regex object is initially instantiated.?
Answer
  • A. var evaluator = new Regex(regexPattern, RegexOptions.CultureInvariant);
  • B. var evaluator = new Regex(input);
  • C. var assemblyName = "Validation"; var compilationInfo = new RegexCompilationInfo(input, RegexOptions.IgnoreCase, "Href", assemblyName, true); Regex.CompileToAssembly(new[] {compilationInfo }, new AssemblyName(assemblyName)); var evaluator = new Regex(regexPattern, RegexOptions.CultureInvariant);
  • D. var evaluator = new Regex(regexPattern, RegexOptions.Compiled);

Question 32

Question
You are developing an application by using C#. You have the following requirements: - Support 32-bit and 64-bit system configurations. - Include pre-processor directives that are specific to the system configuration. - Deploy an application version that includes both system configurations to testers. - Ensure that stack traces include accurate line numbers. Which two actions should you perform to configure the project to avoid changing individual configuration settings every time you deploy the application to testers?
Answer
  • A. Update the platform target and conditional compilation symbols for each application configuration.
  • B. Create two application configurations based on the default Release configuration.
  • C. Optimize the application through address rebasing in the 64-bit configuration.
  • D. Create two application configurations based on the default Debug configuration.

Question 33

Question
You are developing a method named CreateCounters that will create performance counters for an application. The method includes the following code. 01 void CreateCounters() { 02 if(!PerformanceCounterCategory.Exists("Contoso")) { 03 var counters = new counterCreationDataCollection(); 04 var ccdCounter1 = new CounterCreationData { 05 CounterName = "Counter1", 06 CounterType = PerformanceCounterType.SampleFraction 07 }; 08 09 counters.Add(ccdCounter1); 10 var ccdCounter2 = new CounterCreationData { 11 CounterName = "Counter2", 12 <MISSING LINE> 13 }; 12 13 counters.Add(ccdCounter2); 14 PerformanceCounterCategory.Create("Contoso", "Help string", 15 PerformanceCounterCategoryType.MultiInstance, counters); 16 } 17 } Which code segment should you insert at line 15 to ensure that Counter1 is available for use in Windows Performance Monitor (PerfMon)?
Answer
  • A. CounterType = PerformanccCounterType.RawBase
  • B. CounterType = PerformanceCounterType.AverageBase
  • C. CounterType = PerformanceCounterType.SampleBase
  • D. CounterType = PerformanceCounterType.CounterMultiBase

Question 34

Question
You are developing an application that will transmit large amounts of data between a client computer and a server. You need to ensure the validity of the data by using a cryptographic hashing algorithm. Which algorithm should you use?
Answer
  • A. HMACSHA256
  • B. RNGCryptoServiceProvider
  • C. DES
  • D. Aes

Question 35

Question
You are developing an assembly that will be used by multiple applications. You need to install the assembly in the Global Assembly Cache (GAC). Which two actions can you perform to achieve this goal?
Answer
  • A. Use the Assembly Registration tool (regasm.exe) to register the assembly and to copy the assembly to the GAC
  • B. Use the Strong Name tool (sn.exe) to copy the assembly into the GAC
  • C. Use Microsoft Register Server (regsvr32.exe) to add the assembly to the GAC
  • D. Use the Global Assembly Cache tool (gacutil.exe) to add the assembly to the GAC
  • E. Use Windows Installer 2.0 to add the assembly to the GAC

Question 36

Question
You are developing an application by using C#. You provide a public key to the development team during development. You need to specify that the assembly is not fully signed when it is built. Which two assembly attributes should you include in the source code?
Answer
  • A. AssemblyKeyNameAttribute
  • B. ObfuscateAssemblyAttribute
  • C. AssemblyDelaySignAttribute
  • D. AssemblyKeyFileAttribute

Question 37

Question
You are developing an application that accepts the input of dates from the user. Users enter the date in their local format. The date entered by the user is stored in a string variable named inputDate. The valid date value must be placed in a DateTime variable named validatedDate. You need to validate the entered date and convert it to Coordinated Universal Time (UTC). The code must not cause an exception to be thrown. Which code segment should you use?
Answer
  • A. bool validDate = DateTime.TryParse(inputDate, CultureInfo.CurrentCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeLocal, out validatedDate);
  • B. bool validDate = DateTime.TryParse(inputDate, CultureInfo.CurrentCulture, DateTimeStyles.AdjustToUniversal, out validatedDate);
  • C. bool validDate = true; try { validDate = DateTime.Parse(inputDate); } catch { validDate = false; }
  • D. validatedDate = DateTime.ParseExact( inputDate, "g", CultureInfo.CurrentCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal);

Question 38

Question
You are debugging an application that calculates loan interest. The application includes the following code. 01 private static decimal CalculateInterest(decimal loanAmount, int loanTerm, decimal loanRate) { 02 <MISSING CODE> 03 decimal interestAmount = loanAmount * loanRate * loanTerm; 04 05 <MISSING CODE> 06 return interestAmount; 07 } What should you do o ensure that the debugger breaks execution within the CalculateInterest() method when the loanAmount variable is less than or equal to zero in all builds of the application?
Answer
  • A. Insert the following code segment at line 02: Trace.Assert(loanAmount > 0);
  • B. Insert the following code segment at line 02: Debug.Assert(loanAmount > 0);
  • C. Insert the following code segment at line 05: Debug.Write(loanAmount > 0);
  • D. Insert the following code segment at line 05: Trace.Write(loanAmount > 0);

Question 39

Question
You are testing an application. The application includes methods named CalculateInterest and LogLine. The CalculateInterest() method calculates loan interest. The LogLine() method sends diagnostic messages to a console window. You have the following requirements: - The CalculateInterest() method must run for all build configurations. - The LogLine() method must be called only for debug builds. How should you complete the relevant code to ensure the methods run correctly? private static decimal CalculateInterest(decimal loanAmount, int loanTerm, decimal loanRate) { _____decimal interestAmount = loanAmount * loanRate * loanTerm; _____[blank_start]#if DEBUG[blank_end] _____LogLine("Interest Amount: ", interestAmount.ToString("o")); _____[blank_start]#endif[blank_end] _____return interestAmount; } public static void LogLine(string message, string detail) { _____Console.WriteLine("Log: {0} = {1}", message, detail); }
Answer
  • #if DEBUG
  • [Conditional ("RELEASE")]
  • #region DEBUG
  • #endif
  • #endregion
  • [Conditional ("DEBUG")]

Question 40

Question
You are developing an application by using C#. The application will process several objects per second. You need to create a performance counter to analyze the object processing. Which three actions should you perform in sequence? 1. Add the CounterCreationData objects to the collection by calling the Add() method of the collection. 2. Create a PerformanceCounterPermissionEntryCollection collection 3. Call the Create() method of the PerformanceCounterCategory class and pass the collection to the method 4. Get the CategoryName property of the PerformanceCounterPermissionEntry class 5. Create a CounterCreationDataCollection. Then create the counters as CounterCreationData objects and set the necessary properties. Step 1: [blank_start]5[blank_end] Step 2: [blank_start]1[blank_end] Step 3: [blank_start]3[blank_end]
Answer
  • 5
  • 2
  • 4
  • 1
  • 3

Question 41

Question
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. 01 public class Warehouse { 02_______static Inventory _inv = null; 03_______static object _lock = new object(); 04 05_______public static Inventory Inventory { 06___________get { 07________________[blank_start]if (_inv == null)[blank_end] 08______________________[blank_start]lock(_lock);[blank_end] 09________________[blank_start]if(_inv==null)_inv=new Inventory();[blank_end] 10________________return _inv; 11___________} 12______} 13___} 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. Which three code segments should you insert in sequence at line 07 to meet the requirements?
Answer
  • if (_inv == null)
  • if (_inv != null)
  • lock(_lock);
  • if(_inv==null)_inv=new Inventory();
  • if (_inv!=null)_inv=new Inventory();

Question 42

Question
You are adding a public method named UpdateGrade to a public class named ReportCard. The code region that updates the grade field must meet the following requirements: - It must be accessed by only one thread at a time. - It must not be vulnerable to a deadlock situation. What should you do to implement the UpdateGrade() method?
Answer
  • A. Add a private object named lockObject to the ReportCard class. Place the code inside: lock (lockObject) {...}
  • B. Place the code region inside: lock (this) {...}
  • C. Add a public static object named lockObject to the ReportCard class. Place the code inside: lock (typeof(ReportCard)) {...}
  • D. Apply the following attribute to the UpdateGrade() method signature: [MethodImpl(MethodImplOptions.Synchronized)]

Question 43

Question
You are developing an application that includes a class named BookTracker for tracking library books. The application includes the following code segment. 01 public delegate void AddBookCallback(int i); 02 public class BookTracker { 03 List<Book> books = new List<Book>(); 04 05 public void AddBook(string name, AddBookCallback callback) { 06 books.Add(new Book(name)); 07 callback(books.Count); 07 } 07 } 08 09 public class Runner { 10 <MISSING CODE> 11 BookTracker tracker = new BookTracker(); 12 13 public void Add(string name) { 12 <MISSING CODE> 13 } 14 } What should you do to add a user to the BookTracker instance?
Answer
  • A. Insert at 10: private static void PrintBookCount(int i) {...} Insert at 12: AddBookCallback callback = PrintBookCount;
  • B. Insert at 12: tracker.AddBook(name, delegate(int i) {...} );
  • C. Insert at 08: delegate void AddBookDelegate(BookTracker bookTracker); Insert at 12: AddBookDelegate addDelegate = (bookTracker) => {...}; addDelegate(tracker);
  • D. Insert at 08: delegate void AddBookDelegate(string name, AddBookCallback callback); Insert at 12: AddBookDelegate adder = (i, callback) => {...};

Question 44

Question
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: List<User> users = new List<User>(); public void AddUser(string name) { ____User user = new User(name); ____user.Renamed [blank_start]+= (sender, e) =>[blank_end] { _________Log("User {0} was renamed to {1}", e.OldName, e.Name); ____}; ____[blank_start]users.Add(user)[blank_end] } u = user s = sender Public event EventHandler<RenameEventArgs> Renamed; How should you complete the relevant code to create an event handler for the Renamed event by using a lambda expression?
Answer
  • += (sender, e) =>
  • -= delegate(object s,RenamedEventArgs e)
  • += delegate(object s,RenamedEventArgs e)
  • -= (sender, e) =>
  • users.Add(user);
  • users[0] = user;
  • users.Insert(user);

Question 45

Question
You are creating a console application by using C#. You need to access the assembly found in the file named car.dll. Which code segment should you use?
Answer
  • A. Assembly.Load();
  • B. Assembly.GetExecutingAssembly();
  • C. this.GetType();
  • D. Assembly.LoadFile("car.dll");

Question 46

Question
You are developing an application by using C#. The application includes an object that performs a long running process. You need to ensure that the garbage collector does not release the object’s resources until the process completes. Which garbage collector method should you use?
Answer
  • A. WaitForFullGCComplete()
  • B. WaitForFullGCApproach()
  • C. KeepAlive()
  • D. WaitForPendingFinalizers()

Question 47

Question
An application includes a class named Person. The Person class includes a method named GetData. You need to ensure that the GetData() method can be used only by the Person class and not by any class derived from the Person class. Which access modifier should you use for the GetData() method?
Answer
  • A. Public
  • B. Protected Internal
  • C. Internal
  • D. Private
  • E. Protected

Question 48

Question
You are creating an application that manages information about your company’s products. The application includes a class named Product and a method named Save. The Save() method must be strongly typed. It must allow only types inherited from the Product class that use a constructor that accepts no parameters. You need to implement the Save() method. Which code segment should you use?
Answer
  • A. public static void Save(Product target) {...}
  • B. public static void Save<T>(T targer) where T : new(), Product {...}
  • C. public static void Save<T>(T targer) where T : Product {...}
  • D. public static void Save<T>(T targer) where T : Product, new() {...}

Question 49

Question
You are developing an application by using C#. The application will output the text string “First Line” followed by the text string “Second Line”. You need to ensure that an empty line separates the text strings. Which four code segments should you use in sequence? [blank_start]var sb = new StringBuilder();[blank_end] [blank_start]sb.append("first line");[blank_end] [blank_start]sb.AppendLine();[blank_end] [blank_start]sb.append("second line");[blank_end]
Answer
  • var sb = new StringBuilder();
  • sb.Append("/l");
  • sb.append("first line");
  • sb.Append(String.Empty);
  • sb.AppendLine();
  • sb.Append("\t");
  • sb.append("second line");

Question 50

Question
You are developing an application. The application includes classes named Mammal and Animal and an interface named IAnimal. The Mammal class must meet the following requirements: - It must either inherit from the Animal class or implement the IAnimal interface. - It must be inheritable by other classes in the application. Which two code segments can you use to ensure that the Mammal class meets the requirements?
Answer
  • A. abstract class Mammal : IAnimal {...}
  • B. sealed class Mammal : IAnimal {...}
  • C. abstract class Mammal : Animal {...}
  • D. sealed class Mammal : Animal {...}

Question 51

Question
You are developing a class named ExtensionMethods. You need to ensure that the ExtensionMethods class implements the IsEmail() extension method on string objects. How should you complete the relevant code? [blank_start]public static class ExtensionMethods[blank_end] { _____public static bool IsEmail([blank_start]this String str[blank_end]){ __________var regex = new Regex("regex"); __________return regex.IsMatch(str); _____} }
Answer
  • public static class ExtensionMethods
  • protected static class ExtensionMethods
  • public class ExtensionMethods
  • this String str
  • String str

Question 52

Question
You are developing an application by using C#. The application includes the following code segment. 01 public interface IDataContainer { 02 string Data { get; set; } 03 } 04 05 void DoWork(object obj) { 06 <MISSING LINE> 07 if(dataContainer != null) 07 Console.WriteLine(dataContainer.Data); 07 } The DoWork() method must throw an InvalidCastException exception if the obj object is not of type IDataContainer when accessing the Data property. Which code segment should you insert at line 06 to meet the requirements?
Answer
  • A. var dataContainer = (IDataContainer) obj;
  • B. var dataContainer = obj as IDataContamer;
  • C. var dataContainer = obj is IDataContainer;
  • D. dynamic dataContainer = obj;

Question 53

Question
An application receives JSON in the following format: { "FirstName" : "David", "LastName" : "Jones", "Values" : [0, 1, 2] } The application includes the following code segment: 01 public class Name { 02 public int[] Values { get; set; } 03 public string FirstName { get; set; } 04 public string LastName { get; set; } 05 } 06 07 public static Name ConvertToName(string json) { 08 var ser = new JavaScriptSerializer(); 09 <MISSING LINE> 10 } Which code segment should be inserted at line 09 to ensure that ConvertToName() method returns the JSON input string as a Name object?
Answer
  • A. Return ser.Desenalize (json, typeof(Name));
  • B. Return ser.ConvertToType<Name>(json);
  • C. Return ser.Deserialize<Name>(json);
  • D. Return ser.ConvertToType (json, typeof (Name));

Question 54

Question
You are developing an application that includes a class named Customer.The application will output the Customer class as a structured XML document by using the following code segment: <?xml version="1.0" encoding="utf-8"?> <Prospect xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" _xmls:xsd="http://www.w3.org/2001/XMLSchema" _ProspectId="925468724-sdf24554s-s5df4s-s6s54r" xmlns="http://prospect"> _____<FullName>David Jones</FullName> _____<DateOfBirth>1977-06-11T00:00:00</DateOfBirth> </Prospect> How should you complete the relevant code to ensure that the Customer class will serialize to XML? 1. [XmlRoot("Prospect", Namespace = "http://prospect")] 2. [XmlRoot("Customer", Namespace = "http://customer")] [blank_start]1.[blank_end] public class Customer{ [blank_start][XmlAttribute("ProspectId")][blank_end] public Guid Id { get; set; } [blank_start][XmlElement("FullName")][blank_end] public string Name { get; set; } public DateTime DateOfBirth { get; set; } [blank_start][XmlIgnore][blank_end] public int Tin { get; set; } }
Answer
  • 1.
  • 2.
  • [XmlAttribute("ProspectId")]
  • [XmlElement("ProspectId")]
  • [XmlElement("FullName")]
  • [XmlChoiceIdentifier]
  • [XmlArrayItem]
  • [XmlIgnore]

Question 55

Question
An application will upload data by using HTML form-based encoding. The application uses a method named SendMessage. The SendMessage() method includes the following code. 01 public Task<byte[]> SendMessage(string url, int intA, int intB) { 02 var client = new WebClient(); 03 <MISSING CODE> 04 } The receiving URL accepts parameters as form-encoded values. You need to send the values intA and intB as form-encoded values named a and b, respectively. Which code segment should you insert at line 03?
Answer
  • A. var data = string.Format("a{0}&b={1}", intA, intB); return client.UploadStringTaskAsync(new Uri(url), data);
  • B. var data = string.Format("a{0}&b={1}", intA, intB); return client.UploadFileTaskAsync(new Uri(url), data);
  • C. var data = string.Format("a{0}&b={1}", intA, intB); return client.UploadDataTaskAsync(new Uri(url), Encoding.UTF8.GetBytes(data));
  • D. var nvc = new NameValueCollection() { { "a", intA.ToString() }, { "b", intB.ToString() } }; return client.UploadValuesTaskAsync(new Uri(url), Encoding.UTF8.GetBytes(nvc));

Question 56

Question
You are developing an application. The application converts a Location object to a string by using a method named WriteObject. The WriteObject() method accepts two parameters, a Location object and an XmlObjectSerializer object. The application includes the following code. 01 public enum Compass { 02 North, 03 South, 04 East, 05 West 06 } 07 08 [DataContract] 09 public class Location { 10 [DataMember] 11 public string Label { get; set; } 12 [DataMember] 13 public Compass Direction { get; set; } 12 } 13 14 void DoWork() { 15 var location = new Location{ Label = "test", Direction = Compass.West }; 16 Console.WriteLine(WriteObject(location, 17 <MISSING LINE> 18 )); 19 } Which code segment should you insert at line 20 to serialize the Location object as XML
Answer
  • A. New XmlSerializer(typeof(Location))
  • B. New NetDataContractSerializer()
  • C. New DataContractJsonSerializer (typeof (Location) )
  • D. New DataContractSerializer(typeof(Location))

Question 57

Question
You are developing an application that includes a class named Order. The application will store a collection of Order objects. The collection must meet the following requirements: - Internally store a key and a value for each collection item. - Provide objects to iterators in ascending order based on the key. - Ensure that item are accessible by zero-based index or by key. Which collection type should you use to meet the requirements?
Answer
  • A. LinkedList
  • B. Queue
  • C. Array
  • D. HashTable
  • E. SortedList

Question 58

Question
You are developing an application that includes the following code segment 01 using System; 02 class MainClass { 03 public static void Main(string[] args) {} 04 bool bValidInteger = false; 05 int value = 0; 06 07 do { 08 Console.WriteLine("Enter an integer"); 09 bValidInteger = GetValidInteger(ref value); 10 } while (!bValidInteger); 11 12 Console.WriteLine("you eneted a valid integer " + value); 13 } 12 13 public static bool GetValidInteger(ref int val) { 14 string sLine = Console.ReadLine(); 15 int number; 16 <MISSING LINE> 17 return false; 18 else { 19 val = number; 20 return true; 21 } 22 } 23 } Which code segment should you add at line 19 to ensure that the application accepts only integer input and prompts the user each time non-integer input is entered?
Answer
  • 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))

Question 59

Question
You are debugging an application that calculates loan interest. The application includes the following code. 01 private static decimal CalculateInterest(decimal loanAmount, int loanTerm, decimal loanRate) { 02 <MISSING CODE> 03 decimal interestAmount = loanRate * loanTerm * loanAmount; 04 <MISSING CODE> 05 return interestAmount; 06 }
Answer
  • A. Insert at tine 04: Debug.Write(loanAmount > 0);
  • B. Insert at line 04: Trace.Write(loanAmount > 0);
  • C. Insert at line 02: Debug.Assert(loanAmount > 0);
  • D. Insert at line 02: Trace.Assert(loanAmount > 0);

Question 60

Question
You are developing an application that will process orders. The debug and release versions of the application will display different logo images. You need to ensure that the correct image path is set based on the build configuration. Which code segment should you use?
Answer
  • A. #if (DEBUG) imgPath = "TempFolder/Images/"; #elif (RELEASE) imgPath = "DevFolder/Images/"; #endif
  • B. if (DEBUG) imgPath = "TempFolder/Images/"; else imgPath = "DevFolder/Images/"; endif
  • #if (DEBUG) imgPath = "TempFolder/Images/"; #else imgPath = "DevFolder/Images/"; #endif
  • D. if (Debugger.IsAttached) imgPath = "TempFolder/Images/"; else imgPath = "DevFolder/Images/";

Question 61

Question
You are testing an application. The application includes methods named CalculateInterest and LogLine. The CalculateInterest () method calculates loan interest. The LogLine() method sends diagnostic messages to a console window. The following code implements the methods. 01 <MISSING CODE> 02 private static decimal CalculateInterest(decimal loanAmount, int loanTerm, decimal loanRate) { 03 decimal interestAmount = loanAmount * loanTerm * loanTerm; 04 05 <MISSING CODE> 06 LogLine("InterestAmount ", interestAmount.ToString("c")); 07 <MISSING CODE> 08 return interestAmount; 09 } 10 <MISSING CODE> 11 public static void LogLine(string message, string detail) { 12 Console.WriteLine("Log {0} = {1}", message, detail); 13 } You have the following requirements: - The Calculatelnterest() method must run for all build configurations. - The LogLine() method must run only for debug builds. What are two possible ways to ensure that the methods run correctly?
Answer
  • A. Insert at line 01: #region DEBUG Insert at line 10: #endregion
  • B. Insert at line 10: [Conditional("DEBUG”)]
  • C. Insert at line 05: #region DEBUG Insert at line 07: #endregion
  • D. Insert at line 01: #if DEBUG Insert at line 10: #endif
  • E. Insert at line 01: [Conditional("DEBUG”)]
  • F. Insert at line 05: #if DEBUG Insert at line 07: #endif
  • G. Insert at line 10: [Conditional(“RELEASE”)]

Question 62

Question
You are developing a method named CreateCounters that will create performance counters for an application. The method includes the following code. 01 void CreateCounters() { 02 if( !PerformanceCounterCategory.Exists("Contoso")) { 03 var counters = new CounterCreationDataCollection(); 04 var ccdCounter1 = new CounterCreationData { 05 CounterName = "Counter1", 06 CounterType = PerformanceCounterType.AverageTimer32 07 }; 08 counters.Add(ccdCounter1); 09 10 var ccdCounter2 = new CounterCreationData { 11 CounterName = "Counter2", 12 <MISSING LINE> 13 }; 12 counters.Add(ccdCounter2); 13 PerformanceCounterCategory.Create("Contoso", "help string", 14 PerformanceCounterCategoryType.MultiInstance, counters); 15 } 16 } Which code segment should you insert at line 12 to ensure that Counter2 is available for use in Windows Performance Monitor (PerfMon)?
Answer
  • A. CounterType = PerformanccCounterType.RawBase
  • B. CounterType = PerformanceCounterType.AverageBase
  • C. CounterType = PerformanceCounterType.SampleBase
  • D. CounterType = PerformanceCounterType.CounterMultiBase

Question 63

Question
You are developing an application that will transmit large amounts of data between a client computer and a server. You need to ensure the validity of the data by using a cryptographic hashing algorithm. Which algorithm should you use?
Answer
  • A. ECDsa
  • B. RNGCryptoServiceProvider
  • C. Rfc2898DeriveBytes
  • D. HMACSHA512

Question 64

Question
You are implementing a method named FloorTemperature that performs conversions between value types and reference types. The following code segment implements the method. 01 public static void FloorTemperature(float degrees) { 02 object degreesRef = degrees; 03 <MISSING> 04 Console.WriteLine(result); 05 } You need to ensure that the application does not throw exceptions on invalid conversions. Which code segment should you insert at line 04?
Answer
  • A. int result = (int)degreesRef;
  • B. int result = (int)(double)degreesRef;
  • C. int result = degreesRef;
  • D. int result = (int)(float)degreesRef;

Question 65

Question
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: - public class ContosoException : System.Exception {...} - public class ContosoDbException : ContosoException {...} - public class ContosoValidationException : ContosoException {...} The application includes a function named DoWork that throws .NET Framework exceptions and custom exceptions. The application contains only the following logging methods - static void Log (Exception ex) {...} - static void Log (ContosoException ex) {...} - static void Log (ContosoValidationException ex) {...} 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. How should you complete the relevant code to meet the requirements? try { ____Dowork(); } catch ([blank_start]ContosoValidationException ex[blank_end]){ ____Log(ex); } catch ([blank_start]ContosoException ex[blank_end]){ ____Log(ex); } catch ([blank_start]Exception ex[blank_end]) { ____Log(ex); }
Answer
  • ContosoValidationException ex
  • ContosoException ex
  • ContosoDbException ex
  • Exception ex

Question 66

Question
You are developing an application that uses structured exception handling. The application includes a class named Logger. The Logger class implements a method named Log by using the following code segment: public static void Log(Exception ex) { } You have the following requirements: - Log all exceptions by using the Log() method of the Logger class. - Rethrow the original exception, including the entire exception stack. You need to meet the requirements. Which code segment should you use?
Answer
  • A. catch { var ex = new Exception(); throw ex; }
  • B. catch (Exception ex) { Logger.Log(ex); throw ex; }
  • C. catch { Logger.Log(new Exception()); throw; }
  • D. catch (Exception ex) { Logger.Log(ex); throw; }

Question 67

Question
You are developing an application that will include a method named GetData. The GetData() method will retrieve several lines of data from a web service by using a System.IO.StreamReader object. You have the following requirements: - The GetData() method must return a string value that contains the entire response from the web service. - The application must remain responsive while the GetData() method runs. How should you complete the relevant code to implement the GetData() method? public [blank_start]async[blank_end] void GetData(WebResponse response) { _____string urlText; _____var sr = new StreamReader(response.GetResponseStream()); _____urlText = [blank_start]await[blank_end] sr.[blank_start]ReadToEndAsync[blank_end](); }
Answer
  • async
  • await
  • ReadToEndAsync
  • ReadLineAsync
  • ReadLine
  • ReadToEnd
  • ToString
Show full summary Hide full summary

Similar

AQA GCSE Product Design Questions
Bella Statham
English Language Activity Write Up #2 (completed)
08aliell
Language Change Activity Write Up (Completed)
08aliell
How Words Change (the basics)
08aliell
AQA GCSE Product Design Questions
T Andrews
What are the key issues for people experiencing transitions in care discuss using k101 materials
Jen Collins
The Creation of Words
08aliell
SOCIAL, PSYCH AND PHYSICAL ENVIRO(lots of block 4 questions based on this wording)
Jen Collins
Despite its popularity at the time, the Beveridge Report contained some significant drawbacks. What were the strengths and limitations in Beveridge’s vision, and how have later policies addressed these drawbacks?
Jen Collins
What can we learn about life in Lennox Castle from the written and oral records? How far does each type of evidence support the view that Lennox Castle is an example of Goffman’s total institution?
Jen Collins
Biological Molecules - Exam Questions
Mia Weaver