(Line numbers are included for reference only.) 01 bool…
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. (Line numbers are included for reference only.)
01 bool ContainsHyperlink(string inputData)
02 {
03 string regExPattern = “href\\\\s*=\\\\s*(?:\\”(?<1>[^\\”]*)\\”|(?<1>\\\\S+))”;
04
05 return evaluator.IsMatch(inputData);
06 }
The expression patterns used for each validation function are constant. You need to ensure that the expression
syntax is evaluated only once when the Regex object is initially instantiated. Which code segment should you
insert at line 04?
You need to implement the UpdateScore() method
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.
You need to implement the UpdateScore() method. What should you do?
You need to add a user to the UserTracker instance
You are developing an application that includes a class named UserTracker. The application includes the
following code segment. (Line numbers are included for reference only.)
01 public delegate void AddUserCallback(int i);
02 public class UserTracker
03 {
04 List<User> users = new List<User>();
05 public void AddUser(string name, AddUserCallback callback)
06 {
07 users.Add(new User(name));
08 callback(users.Count);
09 }10 }
11
12 public class Runner
13 {
14
15 UserTracker tracker = new UserTracker();
16 public void Add(string name)
17 {
18
19 }
20 }
You need to add a user to the UserTracker instance. What should you do?
Which code segment should you use?
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.
You need to meet the requirements. Which code segment should you use?
Which two actions should you perform?
You are modifying an application that processes leases. The following code defines the Lease class. (Line
numbers are included for reference only.)
01 public class Lease
02 {
03
04 private int _term;
05 private const int MaximumTerm = 5;
06 private const decimal Rate = 0.034m;
07 public int Term
08 {
09 get
10 {
11 return _term;
12 }
13 set
14 {
15 if (value <= MaximumTerm)
16 {
17 _term = value;
18 }
19 else
20 {
21
22 }
23 }
24 }
25 }
26 public delegate void MaximumTermReachedHandler(object source, EventArgs e);
Leases are restricted to a maximum term of 5 years. The application must send a notification message if a
lease request exceeds 5 years. You need to implement the notification mechanism. Which two actions should
you perform? (Each correct answer presents part of the solution. Choose two.)
You need to ensure that the second operation is invoked…
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?
Which code segment should you use?
You are creating a console application by using C#. You need to access the application assembly. Which code
segment should you use?
Which code segment should you insert at line 04?
You are implementing a method named Calculate that performs conversions between value types and
reference types. The following code segment implements the method. (Line numbers are included for reference
only.)
01 public static void Calculate(float amount)
02 {
03 object amountRef = amount;
04
05 Console.WriteLine(balance);
06 }You need to ensure that the application does not throw exceptions on invalid conversions. Which code segment
should you insert at line 04?
Which two actions should you perform?
You are creating a class named Employee. The class exposes a string property named EmployeeType. The
following code segment defines the Employee class. (Line numbers are included for reference only.)
01 public class Employee
02 {
03 internal string EmployeeType
04 {
05 get;
06 set;
07 }
08 }
The EmployeeType property value must be accessed only by code within the Employee class or within a
class derived from the Employee class. The EmployeeType property value must be modified only by code
within the Employee class. You need to ensure that the implementation of the EmployeeType property meets
the requirements. Which two actions should you perform? (Each correct answer represents part of the
complete solution. Choose two.)
Which garbage collector method should you use?
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?