Mock Test 2

  1. You need to write an application in which you create a class that establishes a connection with SQL Server and reads records in a certain table. We need to ensure the following in the class:
    • The class should automatically release all the connections after the operation is complete.
    • The class should support iteration. 

Which of the following interfaces would you implement in the class?

    1. IEnumerator
    2. IEquatable
    3. IComparable
    4. IDisposable
  1. If you need to write a function that could be called with a varying number of parameters, what would you use?
    1. Interface
    2. Method overriding
    3. Method overloading
    4. Lamda expressions
  1. You are writing an application in which you need to reverse a string. Which of the following code snippets would you use?
    1. char[] characters = str.ToCharArray();
      for (int start = 0, end = str.Length - 1; start < end; start++, end--)
      {
          characters[end] = str[start];
          characters[start] = str[end];
      }
      string reversedstring = new string(characters);
      Console.WriteLine(reversedstring);
    2. char[] characters = str.ToCharArray();
      for (int start = 0, end = str.Length - 1; start < end; start++, end--)
      {
          characters[start] = str[end];
          characters[end] = str[start];
      }
      string reversedstring = new string(characters);
      Console.WriteLine(reversedstring);
    3. char[] characters = str.ToCharArray();
      for (int start = 0, end = str.Length; start < end; start++, end--)
      {
          characters[start] = str[end];
          characters[end] = str[start];
      }
      string reversedstring = new string(characters);
      Console.WriteLine(reversedstring);
    4. char[] characters = str.ToCharArray();
      for (int start = 0, end = str.Length; start < end; ++start, end--)
      {
          characters[start] = str[end];
          characters[end] = str[start];
      }
      string reversedstring = new string(characters);
      Console.WriteLine(reversedstring);
  2. Which of the following features of Visual Studio would you use if you needed to compare the memory usage of different builds of the application?
    1. IntelliSense
    2. Use the CPU usage from the performance profiler
    3. Use the memory usage from the performance profiler
    4. Use UI analysis from the performance profiler
  3. Which of the following regex expressions would you use to ensure that the input being validated is a non-negative decimal number?
    1. ^(?!D+$)+?d*?(?:.d*)?$
    2. ^(?:[1-9]d*|0)?(?:.d+)?$
    3. ^d+(.dd)?$
    4. ^(-)?d+(.dd)?$
  4. We are developing an application in which we are using an assembly called X. If we need to debug the code in the assembly, which of the following should we do?
    1. For the application, in Project Build Properties, set the Allow unsafe code property.
    2. For the application, in the Debug pane, in Debugging, set Enable native code and Continue.
    3. For the application, in the Debug pane, in Debugging, uncheck Enable Just My Code.
    4. For the application, in Project Debug Properties, select the Start external program radio button and select assembly X.
  5. We are creating an application with a Student class. We also have a variable called students declared in the application. Which of the following statements would you use to check whether the students variable is of a List of objects of type Student?
    1. if(students.GetType() is List<Student>[])
    2. if(students.GetType() is List<Student>)
    3. if(students is List<Student>[])
    4. if(students is List<Student>)
  1. Which of the following code segments will not result in any loss of data?
    1. public void AddDeposit(float deposit)
      {
          AddToActBalance(Convert.ToDouble(deposit));
      }
      public void AddToActBalance(Double deposit)
      {
      }
    2. public void AddDeposit(float deposit)
      {
          AddToActBalance(Convert.ToDecimal(deposit));
      }
      public void AddToActBalance(Decimal deposit)
      {
      }
    3. public void AddDeposit(float deposit)
      {
          AddToActBalance(Convert.ToInt32(deposit));
      }
      public void AddToActBalance(int deposit)
      {
      }
    4. public void AddDeposit(float deposit)
      {
          AddToActBalance((Decimal)(deposit));
      }
      public void AddToActBalance(Decimal deposit)
      {
      }
  2. We are writing an application in which we need to write some text to a file. The code syntax for this is as follows:
public async void PerformFileWriteOperation()
{
string path = @"InputFile.txt";
string text = "Text to read "
await PerformFileUpdateAsync(path, text);
}
private async Task PerformFileUpdateAsync(string path, string textToUpdate)
{
byte[] encodedBits = Encoding.Unicode.GetBytes(textToUpdate);
using(FileStream stream = new FileStream(
path, FileMode.Append, FileAccess.Write, FileShare.None, bufferSize: 4096, useAsync: true))
{
/// Insert the code here
}
}

Which of the following lines would you insert in the preceding code to ensure the execution is not stopped until the file operation is in progress?

    1. async stream.Write(encodedBits, 0, encodedBits.Length);
    2. await stream.Write(encodedBits,0, encodedBits.Length);
    3. async stream.WriteAsync(encodedBits,0, encodedBits.Length);
    4. await stream.WriteAsync(encodedBits,0, encodedBits.Length);
  1. We are writing an application in which we have written the following code:
public class Car
{
public Car()
{
Console.WriteLine("Inside Car");
}
public void Accelerate()
{
Console.WriteLine("Inside Acceleration of Car");
}
}
public class Ferrari : Car
{
public Ferrari()
{
Console.WriteLine("Inside Ferrari");
}
public void Accelerate()
{
Console.WriteLine("Inside Acceleration of Ferrari");
}
}

class Program
{
static void Main(string[] args)
{
Car b = new Ferrari();
b.Accelerate();
}
}

What would be the output of the program?

    1. Compile-time error
    2. Runtime error
    3. Inside Acceleration of Ferrari
    4. Inside Acceleration of Car
  1. We have an application in which we have written the following logic in a while loop:
int i = 1;
while(i < 10)
{

Console.WriteLine(i);
++i;
}

What would you do to convert it into the equivalent of a for loop?

    1. for (int i = 0; i < 10 ; i++)
      {
          Console.WriteLine(i);
      }
    2. for (int i = 1; i < 10 ; i++)
      {
          Console.WriteLine(i);
      }
    3. for (int i = 1; i < 10 ; ++i)
      {
          Console.WriteLine(i);
      }
    4. for (int i = 1; i <= 10 ; i++)
      {
          Console.WriteLine(i);
      }
  1. What would be the output of the following program?
try
{
int[] input = new int[5] { 0, 1, 2, 3, 4 };
for (int i = 1; i <= 5; i++)
{
Console.Write(input[i]);
}
}
catch (System.IndexOutOfRangeException e)
{
System.Console.WriteLine("An error has occured in collection operation");
throw;
}
catch (System.NullReferenceException e)
{
System.Console.WriteLine("An error has occured in null reference operation");
throw;
}
catch (Exception e)
{
System.Console.WriteLine("Error logged for the application");
}
    1. 01234
    2. 1234
      An error has occurred in collection operation
    3. 1234
      An error has occurred in collection operation
      Error logged for the application
    4. 1234
      An error has occurred in collection operation
      An error has occurred in null reference operation
      Error logged for the application
  1. Delegates can be instantiated by:
    1. Anonymous methods
    2. Lambda expressions
    3. Named methods
    4. All of the above
  1. What action needs to be performed to move a thread to the run state when suspended?
    1. Resume
    2. Interrupt
    3. Abort
    4. Suspended
  2. What would be the output of the following program?
public class DisposeImplementation : IDisposable
{
private bool isDisposed = false;
public DisposeImplementation()
{
Console.WriteLine("Creating object of DisposeImplementation");
}
~DisposeImplementation()
{
if(!isDisposed)
{
Console.WriteLine("Inside the finalizer of class DisposeImplementation");
this.Dispose();
}
}
public void Dispose()
{
isDisposed = true;
Console.WriteLine("Inside the dispose of class DisposeImplementation");

}
}

DisposeImplementation d = new DisposeImplementation();
d.Dispose();
d = null;
GC.Collect();
Console.ReadLine();

    1. Creating object of DisposeImplementation
      Inside the dispose of class DisposeImplementation
      Inside the finalizer of class DisposeImplementation
    2. Creating object of DisposeImplementation
      Inside the dispose of class DisposeImplementation
    3. Runtime error in the application
    4. Creating object of DisposeImplementation
      Inside the finalizer of class DisposeImplementation
      Inside the dispose of class DisposeImplementation
  1. Look at the following program:
static int CalculateResult(int parameterA, int parameterB, int parameterC, int parameterD = 0)
{
int result = ((parameterA + parameterB) / (parameterC - parameterD));
return result;
}

What would be the output when it is called using the following syntax?

CalculateResult(parameterA: 20, 15, 5)
    1. -7
    2. 1
    3. 7
    4. Run time error
  1. Which of these can be used to authenticate user input?
    1. Symmetric algorithm
    2. Asymmetric algorithm
    3. Hash values
    4. Digital signatures
  1. We are working with a large group of student objects. You need to use a data structure that allows access to elements in any order and also allows duplicate values without needing to group them under a particular key. What would you choose?
    1. List
    2. Stack
    3. Dictionary
    4. Queue
  2. Your application is running multiple worker threads. How do you make sure your application waits for all threads to complete their execution?
    1. Thread.Sleep()
    2. Thread.WaitAll()
    3. Thread.Join()
    4. None
  3. In an application, we are writing a method in a class that should be accessible to classes in the same class and in classes that are present in the same assembly that inherit from the class. What do you need?
    1. Private protected
    2. Protected internal
    3. Protected
    4. Internal
..................Content has been hidden....................

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