Which code segment should you add at line 19?
You are developing an application that includes the following code segment. (Line numbers are included for
reference only.)
01 using System;
02 class MainClass
03 {
04 public static void Main(string[] args)
05 {
06 bool bValidInteger = false;
07 int value = 0;
08 do
09 {
10 Console.WriteLine(“Enter an integer”);
11 bValidInteger = GetValidInteger(ref value);
12 } while (!bValidInteger);
13 Console.WriteLine(“You entered a valid integer, ” + value);
14 }
15 public static bool GetValidInteger(ref int val)
16 {
17 string sLine = Console.ReadLine();
18 int number;
19
20 {
21 return false;
22 }
23 else
24 {
25 val = number;
26 return true;
27 }
28 }
29 }
You need to ensure that the application accepts only integer input and prompts the user each time non-integer
input is entered. Which code segment should you add at line 19?
Which collection type should you use?
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.
You need to use a collection type that meets the requirements. Which collection type should you use?
Which code segment should you insert at line 20?
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. (Line numbers are included for
reference only.)
01 public enum Compass
02 {
03 North,
04 South,
05 East,
06 West
07 }
08 [DataContract]
09 public class Location
10 {
11 [DataMember]
12 public string Label { get; set; }
13 [DataMember]
14 public Compass Direction { get; set; }
15 }
16 void DoWork()
17 {
18 var location = new Location { Label = “Test”, Direction = Compass.West};
19 Console.WriteLine(WriteObject(location,
20
21 ));
22 }
You need to serialize the Location object as XML. Which code segment should you insert at line 20?
Which code segment should you insert at line 04?
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. (Line numbers are included for
reference only.)
01 public Task<byte[]> SendMessage(string url, int intA, int intB)
02 {
03 var client = new WebClient();
04
05 }
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 04?
Which two actions should you perform?
You are developing an application that includes the following code segment. (Line numbers are included for
reference only.)
01 class Customer
02 {
03 public string CompanyName { get; set; }
04 public string Id { get; set; }
05 }
06 const string sqlSelectCustomerss = “SELECT CustomerID, CompanyName FROM
Customers”;
07 private static IEnumerable<Customer> GetCustomers(string sqlConnectionString)
08 {
09 List<Customer> customers = new List<Customer>();
10 SqlConnection sqlConnection = new SqlConnection(sqlConnectionString);
11 using (sqlConnection)
12 {
13 SqlCommand sqlCommand = new SqlCommand(sqlSelectCustomers,
sqlConnection);
14
15 using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
16 {17
18 {
19 Customer customer = new Customer();
20 customer.Id = (string)sqlDataReader[“CustomerID”];
21 customer.CompanyName = (string)sqlDataReader[“CompanyName”];
22 customers.Add(customer);
23 }
24 }
25 }
26 return customers;
27 }
The GetCustomers() method must meet the following requirements:
connect to a Microsoft SQL Server database.
populate Customer objects with data from the database.
return an IEnumerable<Customer> collection that contains the populated Customer objects.
You need to meet the requirements. Which two actions should you perform? (Each correct answer presents
part of the solution. Choose two.)
Which code segment should you insert at line 07?
You are developing an application by using C#. The application includes the following code segment. (Line
numbers are included for reference only.)
01 public interface IDataContainer
02 {
03 string Data { get; set; }
04 }
05 void DoWork(object obj)
06 {
07
08 if (dataContainer != null)
09 {
10 Console.WriteLine(dataContainer.Data);
11 }
12 }
The DoWork() method must throw an InvalidCastException exception if the obj object is not of type
IDataContainer when accessing the Data property. You need to meet the requirements. Which code
segment should you insert at line 07?
Which two code segments can you use to achieve this goal?
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.
You need to ensure that the Mammal class meets the requirements. Which two code segments can you use to
achieve this goal? (Each correct answer presents a complete solution. Choose two.)
Which code segment should you use?
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?
Which access modifier should you use for the GetData() …
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?
Which code segment should you use?
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?