Mock Test 1

  1. We have a class called LogException. The class implements a CaptureException method using the following code segment: public static void CaptureException(Exception ex). Pick one of the following syntaxes to make sure all exceptions in the class are captured and rethrow the original exception, including the stack:
    1. catch (Exception ex)
      {
          LogException.CaptureException(ex);
          throw;
      }

    2. catch (Exception ex)
      {
          LogException.CaptureException(ex);
          throw ex;
      }

    3. catch
      {
          LogException(new Exception());
      }

    4. catch
      {
          var ex = new Exception();
          throw ex;
      }

  2. You are creating a class named Store, which should have a Store Type member that meets the following requirements:
    • The member must be accessible publicly.
    • The member must only acquire a restricted set of values.
    • While setting the value, the member must ensure that it validates the input set in the member.

In which form should you implement the score member?

    1. public string storeType;
    2. protected String StoreType
      {
          get{}
          set{}
      }
    3. private enum StoreType { Department, Store, Warehouse}
      public StoreType  StoreTypeProperty

           get{}
           set{}
      }
    4. private enum StoreType { Department, Store, Warehouse}
      private StoreType  StoreTypeProperty
      {
          get{}
          set{}
      }
  1. Write an extension method for a string; it should have an IsEmail method . The method should check whether the string is a valid email. Select the syntax and map it to the places where it should be placed:
----------------------/*Line which needs to be filled*/
{
------------------/*Line which needs to be filled*/
{
Regex regex = new Regex(@"^([w.-]+)@([w-]+)((.(w){2,3})+)$");
return regex.IsMatch(str);
}
}
    1. protected static class StringExtensions
    2. public static class StringExtensions
    3. public static bool IsEmail(this String str)
    4. public static bool IsEmail(String str)
    5. public class StringExtensions
  1. You need to write an application in which we ensure that the garbage collector does not release an object's resources until the process completes. Which of the following syntaxes would you use?
    1. WaitForFullGCComplete()
    2. RemoveMemoryPressure()
    3. SuppressFinalize()
    4. collect()
  2. For a list collection, someone has written the following code:
static void Main(string[] args)
{
List<string> states = new List<string>()
{
"Delhi", "Haryana", "Assam", "Punjab", "Madhya Pradesh"
};
}

private bool GetMatchingStates(List<string> states, string stateName)
{
var findState = states.Exists(delegate(
string stateNameToSearch)
{
return states.Equals(stateNameToSearch);
});
return findState;
}

Which of the following code segments is the correct representation of the corresponding Lambda expression?

    1. var findState = states.First(x => x == stateName);
    2. var findState = states.Where(x => x == stateName);
    3. var findState = states.Exists(x => x.Equals(stateName));
    4. var findState = states.Where(x => x.Equals(stateName));
  1. Which of the following collection objects would fulfill the following requirements?
    • It must internally store a key and value pair for each item.
    • It must allow us to iterate over the collection in order of the key.
    • It allows us to access the objects using the key.

The collection objects are as follows:

    1. Dictionary
    2. Stack
    3. List
    4. SortedList
  1. You are creating an application that has a Student class. The application must have a Save method that should satisfy the following:
    • It must be strongly typed.
    • The method must only accept types inherited from the Animal class that use a constructor that accepts no parameters.

The options are as follows:

    1. public static void Save(Student target)
      {
      }
    2. public static void Save<T>(T target) where T : Student , new()
      {
      }
    3. public static void Save<T>(T target) where T : new(), Student
      {
      }
    4. public static void Save<T>(T target) where T : Student
      {
      }
  1. We are writing an application that is receives a JSON input from another application in the following format:
{
"StudentFirstName" : "James",
"StudentLastName" : "Donohoe",
"StudentScores" : [45, 80, 68]
}

We have written the following code in our application to process the input. What would be the correct syntax in the ConvertFromJSON method to ensure that we convert the input to its equivalent student format?

public class Student
{
public string StudentFirstName {get; set;}
public string StudentLastName {get; set;}
public int[] StudentScores {get; set;}
}

public static Student ConvertFromJSON(string json)
{
var ser = new JavaScriptSerializer();
----------------/*Insert a line here*/
}

The options are as follows:

    1. Return ser.Desenalize (json, typeof(Student));
    2. Return ser.ConvertToType<Student>(json);
    3. Return ser.Deserialize<Student>(json);
    4. Return ser.ConvertToType (json, typeof (Student));
  1. You have an array of integers with studentId values in them. Which code logic would you use to do the following?
    • Only select the unique studentID
    • Remove a particular studentID from the array
    • Sort the result in descending order into another array

Your options are as follows:

    1. int[] filteredStudentIDs = studentIDs.Distinct().Where(value => value != studentIDToRemove).OrderByDescending(x => x).ToArray();
    2. int[] filteredStudentIDs = studentIDs.Where(value => value != studentIDToRemove).OrderBy(x => x).ToArray();
    3. int[] filteredStudentIDs = studentIDs.Where(value => value != studentIDToRemove).OrderByDescending(x => x).ToArray();
    4. int[] filteredStudentIDs = studentIDs.Distinct().OrderByDescending(x => x).ToArray();
  1. Identify the missing line in the following line of code:
private static IEnumerable<Country> ReadCountriesFromDB(string sqlConnectionString)
{
List countries = new List<Country>();
SqlConnection conn = new SqlConnection();
using (sqlConnectionString)
{
SqlCommand sqlCmd = new SqlCommand("Select name, continent
from Counties", sqlConnectionString);
conn.Open();
using (SqlDataReader reader = sqlCmd.ExecuteReader())
{
// Insert the Line Here
{
Country con = new Country();
con.CountryName = (String)reader["name"];
con.ContinentName = (String)reader["continent"];
counties.Add(con);
}
}
}
return countries;
}
    1. while (reader.Read())
    2. while (reader.NextResult())
    3. while (reader.Being())
    4. while (reader.Exists())
  1. Write the following StudentCollection class in such a way that you can process each object in the collection using a foreach loop:
public class StudentCollection //Insert Code Here
{
private Student[] students;
public StudentCollection(Student[] student)
{
students = new Student[student.Length];

for (int i=0; i< student.Length; i++)
{
students[i] = student[i];
}
}

//Insert Code Here
{
//Insert Code Here
}
}
    1. : IComparable
    2. : IEnumerable
    3. : IDisposable
    4. public void Dispose()
    5. return students.GetEnumerator();
    6. return obj == null ? 1: students.Length;
    7. public IEnumerator GetEnumerator()
  1. Which of the following lines of code would you use if you are writing code to open a file in line with the following conditions?
    • No changes should be made to the file.
    • The application should throw an error if the file does not exist.
    • No other processes should be allowed to update this file while the operation is in progress.
    1. var fs = File.Open(Filename, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite);
    2. var fs = File.Open(Filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
    3. var fs = File.Open(Filename, FileMode.Open, FileAccess.Read, FileShare.Read);
    4. var fs = File.Open(Filename, FileMode.Open, FileAccess.ReadWrite, FileShare.Read);
  1. Which of the following lines of code would you use while converting a float to an int? You need to ensure that the conversion will not throw the Float floatPercentage; exception:
    1. int roundPercentage = (int)floatPercentage;
    2. int roundPercentage = (int)(double)floatPercentage;
    3. int roundPercentage = floatPercentage;
    4. int roundPercentage = (int)(float)floatPercentage;
  2. Which of the following lines of code would you use while converting a float to an int? You need to ensure that the conversion will not throw the Float floatPercentage; exception: 
    1. int roundPercentage = (int)floatPercentage;
    2. int roundPercentage = (int)(double)floatPercentage;
    3. int roundPercentage = floatPercentage;
    4. int roundPercentage = (int)(float)floatPercentage;
  3. We are creating a Student class with a StudentType attribute. We need to ensure that the StudentType property can only be accessed within the Student class or by a class inheriting from the the Student class. Which of the following  implementations would you use?
    1. public class Student
      {
          protected string StudentType
          {
              get;
              set;
          }
      }
    2. public class Student
      {
          internal string StudentType
          {
              get;
              set;
          }
      }
    3. public class Student
      {
          private string StudentType
          {
              get;
              set;
          }
      }
    4. public class Student
      {
          public string StudentType
          {
              get;
              set;
          }
      }
  4. We are writing an application in which we have declared a Car class that has two attributes, CarCategory and CarName. In the execution, we need to convert the class to its JSON string representation. Refer to the following code snippet:
public enum CarCategory
{
Luxury,
Sports,
Family,
CountryDrive
}

[DataContract]
public class Car
{
[DataMember]
public string CarName { get; set; }
[DataMember]
public enum CarCategory { get; set; }
}

void ShareCareDetails()
{
var car = new Car { CarName = "Mazda", CarCategory = CarCategory.Family };
var serializedCar = /// Insert the code here
}

Which of the following lines of code would you use to get the correct structure for the JSON representation?

    1. new DataContractSerializer(typeof(Car))
    2. new XmlSerializer(typeof(Car))
    3. new NetDataContractSerializer()
    4. new DataContractJsonSerializer(typeof(Car))
  1. We are writing an application for a bank in which we use the following code to find out the interest amount for a specified number of months, and the initial amount deposited in the bank:
1   private static decimal CalculateBankAccountInterest(decimal initialAmount, int numberOfMonths)
2 {
3 decimal interestAmount;
4 decimal interest;
5 if(numberOfMonths > 0 && numberOfMonths < 6 && initialAmount < 5000)
6 {
7 interest = 0.05m;
8 }
9 else if(numberOfMonths > 6 && initialAmount > 5000)
10 {
11 interest = 0.065m;
12 }
13 else
14 {
15 interest = 0.06m;
16 }
17
18 interestAmount = interest * initialAmount * numberOfMonths / 12;
19 return interestAmount;
20 }

We've learned that the application is calculating incorrect interest amounts if the number of months is 6. If the number of months is 6, the interest rate should be 6.2%. Which of the lines of code would you change?

    1. Replace line 7 with interest = 0.062m
    2. Replace line 11 with interest = 0.06m
    3. Replace line 4 with decimal interest = 0.062m
    4. Replace line 15 with interest = 0.062m
  1. We are writing an application in which we are making asynchronous calls to three different services, as described in the following example:
public async Task ExecuteMultipleRequestsInParallel() 
{
HttpClient client = new HttpClient();
Task task1 = client.GetStringAsync("ServiceUrlA");
Task task2 = client.GetStringAsync("ServiceUrlB");
Task task3 = client.GetStringAsync("ServiceUrlC");
// Insert the call here
}

Which of the following lines would you insert if you need to wait for the results from all three preceding services before control can be transferred back to the calling function?

    1. await Task.Yield();
    2. await Task.WhenAll(task1, task2, task3);
    3. await Task.WaitForCompletion(task1, task2, task3);
    4. await Task.WaitAll();
  1. We are writing an application in which we are executing multiple operations, such as assigning, modifying, and replacing on string variables. Which of the following keywords would you use to make sure the operations consume as little memory as possible?
    1. String.Concat
    2. + operator
    3. StringBuilder
    4. String.Add
  1. We are writing an application in which we are maintaining students scores in a list, as shown in the following code block. We need to write a statement to filter out scores greater that 75. Which of the statements would you use?
List<int> scores = new List<int>()
{
90,
55,
80,
65
};
    1. var filteredScores = scores.Skip(75);
    2. var filteredScores = scores.Where(i => i > 75);
    3. var filteredScores = scores.Take(75);
    4. var filteredScores = from i in scores
      groupby i into tempList
      where tempList.Key > 75
      select i;
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.136.18.141