Paige Gentry
Quiz by , created more than 1 year ago

Certificate 70-483: Programming in C# (Exam Questions) Quiz on 70-483: Exam Questions, created by Paige Gentry on 15/06/2016.

268
1
0
Paige Gentry
Created by Paige Gentry almost 8 years ago
Close

70-483: Exam Questions

Question 1 of 67

1

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?

Select one of the following:

  • 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();

Explanation

Question 2 of 67

1

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?

Select one of the following:

  • Queue<T>

  • SortedList

  • LinkedList<T>

  • HashTable

  • Array<T>

Explanation

Question 3 of 67

1

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?

Select one or more of the following:

  • 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() )

Explanation

Question 4 of 67

1

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 {
....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];
........}
....}
....
........
....}
}

Drag and drop to complete the text.

    : 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

Explanation

Question 5 of 67

1

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?

Select one of the following:

  • 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

Explanation

Question 6 of 67

1

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 =
amount in loanAmounts
amount % 2 == 0
amount
amount;

Drag and drop to complete the text.

    from
    join
    where
    group
    orderby
    descending
    select
    ascending

Explanation

Question 7 of 67

1

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?

Select one of the following:

  • 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);

Explanation

Question 8 of 67

1

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?

Select one of the following:

  • A. Return ser.ConvertToType<Name> ( json );

  • B. Return ser.DeserializeObject( json );

  • C. Return ser.Deserialize<Name> ( json );

  • D. Return (Name)ser.Serialize( json );

Explanation

Question 9 of 67

1

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?


class Name {
......
......public string FirstName { get; set; }

......
......public string LastName { get; set; }
}

Drag and drop to complete the text.

    [DataContract ( Namespace = "xmlns")]
    [DataContract ( Name="xmlns", Order=10)]
    [DataContract ( Name = "xmlns")]
    [DataContract]
    [DataMember ( Name = "xmlns")]
    [DataMember ( Order = 10 )]
    [DataMember]

Explanation

Question 10 of 67

1

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?

Select one of the following:

  • A. New DataContractSerializer( typeof ( Location ) )

  • B. New XmlSerializer ( typeof ( Location ) )

  • C. New NetDataContractSerializer()

  • D. New DataContractJsonSerializer ( typeof (Location ) )

Explanation

Question 11 of 67

1

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?

Select one of the following:

  • A. Internal

  • B. Protected

  • C. Private

  • D. Protected Internal

  • E. Public

Explanation

Question 12 of 67

1

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?

Select one of the following:

  • A. var dataContainer = ( IDataContainer ) obj;

  • B. dynamic dataContainer = obj;

  • C. var dataContainer = obj is IDataContainer;

  • D. var dataContainer = obj as IDataContainer;

Explanation

Question 13 of 67

1

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?

Select one of the following:

  • 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) {...}

Explanation

Question 14 of 67

1

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?

{
.......public static bool IsUrl( ) {
..............var regex = new Regex("Regex expressions" + "More regex expressions" );
..............return regex.IsMatch(str);
.......}

Drag and drop to complete the text.

    public static class ExtensionMethods
    public class ExtensionMethods
    protected static class ExtensionMethods
    this String str
    String str

Explanation

Question 15 of 67

1

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?

Select one or more of the following:

  • A. sealed class Employee : Person {...}

  • B. abstract class Employee : Person {...}

  • C. sealed class Employee : IPerson {...}

  • D. abstract class Employee : IPerson {...}

Explanation

Question 16 of 67

1

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

Select one of the following:

  • 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;

Explanation

Question 17 of 67

1

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?

Select one of the following:

  • A. ReRegisterForFinalize()

  • B. SuppressFinalize()

  • C. Collect()

  • D. WaitForFullGCApproach()

Explanation

Question 18 of 67

1

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?

Select one or more of the following:

  • 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;

Explanation

Question 19 of 67

1

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?

Select one of the following:

  • A. int balance = (int) (float)amountRef;

  • B. int balance = (int)amountRef;

  • C. int balance = amountRef;

  • D. int balance = (int) (double)AmountRef;

Explanation

Question 20 of 67

1

You are creating a console application by using C#. You need to access the application assembly. Which code segment should you use?

Select one of the following:

  • A. Assembly.GetAssembly(this);

  • B. this.GetType();

  • C. Assembly.Load();

  • D. Assembly.GetExecutingAssembly();

Explanation

Question 21 of 67

1

Select from the dropdown lists to complete the text.

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;
___( switch, case, if ) (letter) {
______( case, default, else, if ) 'a':
_________response = "animal";
_________break;
______( case, default, else, if ) 'm':
_________response = "mineral";
_________break;
______( case, default, else, if ):
_________response = "invalid choice";
_________break;
___}
___return response;
}

Explanation

Question 22 of 67

1

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?

Select one of the following:

  • 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.

Explanation

Question 23 of 67

1

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?

Select one or more of the following:

  • 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

Explanation

Question 24 of 67

1

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?

Select one of the following:

  • 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;
    }

Explanation

Question 25 of 67

1

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?

Select one of the following:

  • 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) {...}; )

Explanation

Question 26 of 67

1

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 (("log.txt")) {
______try {
____________string line;
____________while((line = sr.ReadLine()) != null)
__________________Console.WriteLine(line);
______}
______catch(FileNotFoundException e){
____________Console.Write(e.ToString());
____________
______}
}

Drag and drop to complete the text.

    StreamReader sr = new StreamReader
    StringReader sr = new StringReader
    throw;
    throw new FileNotFoundException();

Explanation

Question 27 of 67

1

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____________________ Catalog();
08____________________
09_________________________
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?

Drag and drop to complete the text.

    if(_catalog != null)
    if(_catalog == null)
    lock(_lock);
    if(_catalog != null) _catalog = new
    if(_catalog == null) _catalog = new

Explanation

Question 28 of 67

1

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 void GetData(WebResponse response) {
_____var streamReader = new StreamReader(response.GetREsponseStream());

_____urlText.Text = streamReader.
}

Drag and drop to complete the text.

    async
    ToString();
    await
    ReadToEnd();
    ReadLineAsync();
    ReadLine();
    ReadToEndAsync();

Explanation

Question 29 of 67

1

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?

Select one of the following:

  • 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)) {...}

Explanation

Question 30 of 67

1

You are developing an application that implements a set of custom exception types. You declare the custom exception types by using the following code segments:

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 (){
_____Log(ex);
}
catch (){
_____Log(ex);
}
catch ( ex){
_____Log(ex);
}

Drag and drop to complete the text.

    AdventureWorksValidationException ex
    ContosoDbException ex
    AdventureWorksException ex
    Exception

Explanation

Question 31 of 67

1

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.?

Select one of the following:

  • 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);

Explanation

Question 32 of 67

1

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?

Select one or more of the following:

  • 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.

Explanation

Question 33 of 67

1

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)?

Select one of the following:

  • A. CounterType = PerformanccCounterType.RawBase

  • B. CounterType = PerformanceCounterType.AverageBase

  • C. CounterType = PerformanceCounterType.SampleBase

  • D. CounterType = PerformanceCounterType.CounterMultiBase

Explanation

Question 34 of 67

1

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?

Select one of the following:

  • A. HMACSHA256

  • B. RNGCryptoServiceProvider

  • C. DES

  • D. Aes

Explanation

Question 35 of 67

1

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?

Select one or more of the following:

  • 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

Explanation

Question 36 of 67

1

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?

Select one or more of the following:

  • A. AssemblyKeyNameAttribute

  • B. ObfuscateAssemblyAttribute

  • C. AssemblyDelaySignAttribute

  • D. AssemblyKeyFileAttribute

Explanation

Question 37 of 67

1

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?

Select one of the following:

  • 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);

Explanation

Question 38 of 67

1

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?

Select one of the following:

  • 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);

Explanation

Question 39 of 67

1

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;

_____
_____LogLine("Interest Amount: ", interestAmount.ToString("o"));
_____

_____return interestAmount;
}
public static void LogLine(string message, string detail) {
_____Console.WriteLine("Log: {0} = {1}", message, detail);
}

Drag and drop to complete the text.

    #if DEBUG
    [Conditional ("RELEASE")]
    #region DEBUG
    #endif
    #endregion
    [Conditional ("DEBUG")]

Explanation

Question 40 of 67

1

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:
Step 2:
Step 3:

Drag and drop to complete the text.

    5
    2
    4
    1
    3

Explanation

Question 41 of 67

1

You are developing an application that includes a class named Warehouse. The Warehouse class includes a static property named Inventory- The Warehouse class is defined by the following code segment.

01 public class Warehouse {
02_______static Inventory _inv = null;
03_______static object _lock = new object();
04
05_______public static Inventory Inventory {
06___________get {
07________________
08______________________
09________________
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?

Drag and drop to complete the text.

    if (_inv == null)
    if (_inv != null)
    lock(_lock);
    if(_inv==null)_inv=new Inventory();
    if (_inv!=null)_inv=new Inventory();

Explanation

Question 42 of 67

1

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?

Select one of the following:

  • 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)]

Explanation

Question 43 of 67

1

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?

Select one of the following:

  • 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) => {...};

Explanation

Question 44 of 67

1

You are implementing a method that creates an instance of a class named User. The User class contains a public event named Renamed. The following code segment defines the Renamed event:

List<User> users = new List<User>();
public void AddUser(string name) {
____User user = new User(name);
____user.Renamed {
_________Log("User {0} was renamed to {1}", e.OldName, e.Name);
____};
____
}

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?

Drag and drop to complete the text.

    += (sender, e) =>
    -= delegate(object s,RenamedEventArgs e)
    += delegate(object s,RenamedEventArgs e)
    -= (sender, e) =>
    users.Add(user);
    users[0] = user;
    users.Insert(user);

Explanation

Question 45 of 67

1

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?

Select one of the following:

  • A. Assembly.Load();

  • B. Assembly.GetExecutingAssembly();

  • C. this.GetType();

  • D. Assembly.LoadFile("car.dll");

Explanation

Question 46 of 67

1

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?

Select one of the following:

  • A. WaitForFullGCComplete()

  • B. WaitForFullGCApproach()

  • C. KeepAlive()

  • D. WaitForPendingFinalizers()

Explanation

Question 47 of 67

1

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?

Select one of the following:

  • A. Public

  • B. Protected Internal

  • C. Internal

  • D. Private

  • E. Protected

Explanation

Question 48 of 67

1

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?

Select one of the following:

  • 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() {...}

Explanation

Question 49 of 67

1

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?




Drag and drop to complete the text.

    var sb = new StringBuilder();
    sb.Append("/l");
    sb.append("first line");
    sb.Append(String.Empty);
    sb.AppendLine();
    sb.Append("\t");
    sb.append("second line");

Explanation

Question 50 of 67

1

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?

Select one or more of the following:

  • A. abstract class Mammal : IAnimal {...}

  • B. sealed class Mammal : IAnimal {...}

  • C. abstract class Mammal : Animal {...}

  • D. sealed class Mammal : Animal {...}

Explanation

Question 51 of 67

1

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?

{
_____public static bool IsEmail(){
__________var regex = new Regex("regex");
__________return regex.IsMatch(str);
_____}
}

Drag and drop to complete the text.

    public static class ExtensionMethods
    protected static class ExtensionMethods
    public class ExtensionMethods
    this String str
    String str

Explanation

Question 52 of 67

1

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?

Select one of the following:

  • A. var dataContainer = (IDataContainer) obj;

  • B. var dataContainer = obj as IDataContamer;

  • C. var dataContainer = obj is IDataContainer;

  • D. dynamic dataContainer = obj;

Explanation

Question 53 of 67

1

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?

Select one of the following:

  • 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));

Explanation

Question 54 of 67

1

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")]


public class Customer{

public Guid Id { get; set; }


public string Name { get; set; }

public DateTime DateOfBirth { get; set; }


public int Tin { get; set; }
}

Drag and drop to complete the text.

    1.
    2.
    [XmlAttribute("ProspectId")]
    [XmlElement("ProspectId")]
    [XmlElement("FullName")]
    [XmlChoiceIdentifier]
    [XmlArrayItem]
    [XmlIgnore]

Explanation

Question 55 of 67

1

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?

Select one of the following:

  • 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));

Explanation

Question 56 of 67

1

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

Select one of the following:

  • A. New XmlSerializer(typeof(Location))

  • B. New NetDataContractSerializer()

  • C. New DataContractJsonSerializer (typeof (Location) )

  • D. New DataContractSerializer(typeof(Location))

Explanation

Question 57 of 67

1

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?

Select one of the following:

  • A. LinkedList

  • B. Queue

  • C. Array

  • D. HashTable

  • E. SortedList

Explanation

Question 58 of 67

1

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?

Select one of the following:

  • 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))

Explanation

Question 59 of 67

1

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 }

Select one of the following:

  • 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);

Explanation

Question 60 of 67

1

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?

Select one of the following:

  • 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/";

Explanation

Question 61 of 67

1

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?

Select one or more of the following:

  • 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”)]

Explanation

Question 62 of 67

1

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)?

Select one of the following:

  • A. CounterType = PerformanccCounterType.RawBase

  • B. CounterType = PerformanceCounterType.AverageBase

  • C. CounterType = PerformanceCounterType.SampleBase

  • D. CounterType = PerformanceCounterType.CounterMultiBase

Explanation

Question 63 of 67

1

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?

Select one of the following:

  • A. ECDsa

  • B. RNGCryptoServiceProvider

  • C. Rfc2898DeriveBytes

  • D. HMACSHA512

Explanation

Question 64 of 67

1

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?

Select one of the following:

  • A. int result = (int)degreesRef;

  • B. int result = (int)(double)degreesRef;

  • C. int result = degreesRef;

  • D. int result = (int)(float)degreesRef;

Explanation

Question 65 of 67

1

You are developing an application that implements a set of custom exception types. You declare the custom exception types by using the following code segments:
- 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 (){
____Log(ex);
}
catch (){
____Log(ex);
}
catch () {
____Log(ex);
}

Drag and drop to complete the text.

    ContosoValidationException ex
    ContosoException ex
    ContosoDbException ex
    Exception ex

Explanation

Question 66 of 67

1

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?

Select one of the following:

  • 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;
    }

Explanation

Question 67 of 67

1

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 void GetData(WebResponse response) {
_____string urlText;
_____var sr = new StreamReader(response.GetResponseStream());
_____urlText = sr.();
}

Drag and drop to complete the text.

    async
    await
    ReadToEndAsync
    ReadLineAsync
    ReadLine
    ReadToEnd
    ToString

Explanation