- 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?
-
- IEnumerator
- IEquatable
- IComparable
- IDisposable
- If you need to write a function that could be called with a varying number of parameters, what would you use?
-
- Interface
- Method overriding
- Method overloading
- Lamda expressions
- You are writing an application in which you need to reverse a string. Which of the following code snippets would you use?
- 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); - 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); - 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); - 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);
- char[] characters = str.ToCharArray();
- 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?
- IntelliSense
- Use the CPU usage from the performance profiler
- Use the memory usage from the performance profiler
- Use UI analysis from the performance profiler
- Which of the following regex expressions would you use to ensure that the input being validated is a non-negative decimal number?
- ^(?!D+$)+?d*?(?:.d*)?$
- ^(?:[1-9]d*|0)?(?:.d+)?$
- ^d+(.dd)?$
- ^(-)?d+(.dd)?$
- 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?
- For the application, in Project Build Properties, set the Allow unsafe code property.
- For the application, in the Debug pane, in Debugging, set Enable native code and Continue.
- For the application, in the Debug pane, in Debugging, uncheck Enable Just My Code.
- For the application, in Project Debug Properties, select the Start external program radio button and select assembly X.
- 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?
- if(students.GetType() is List<Student>[])
- if(students.GetType() is List<Student>)
- if(students is List<Student>[])
- if(students is List<Student>)
- Which of the following code segments will not result in any loss of data?
- public void AddDeposit(float deposit)
{
AddToActBalance(Convert.ToDouble(deposit));
}
public void AddToActBalance(Double deposit)
{
} - public void AddDeposit(float deposit)
{
AddToActBalance(Convert.ToDecimal(deposit));
}
public void AddToActBalance(Decimal deposit)
{
} - public void AddDeposit(float deposit)
{
AddToActBalance(Convert.ToInt32(deposit));
}
public void AddToActBalance(int deposit)
{
} - public void AddDeposit(float deposit)
{
AddToActBalance((Decimal)(deposit));
}
public void AddToActBalance(Decimal deposit)
{
}
- public void AddDeposit(float deposit)
- 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?
-
- async stream.Write(encodedBits, 0, encodedBits.Length);
- await stream.Write(encodedBits,0, encodedBits.Length);
- async stream.WriteAsync(encodedBits,0, encodedBits.Length);
- await stream.WriteAsync(encodedBits,0, encodedBits.Length);
- 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?
-
- Compile-time error
- Runtime error
- Inside Acceleration of Ferrari
- Inside Acceleration of Car
- 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?
-
- for (int i = 0; i < 10 ; i++)
{
Console.WriteLine(i);
} - for (int i = 1; i < 10 ; i++)
{
Console.WriteLine(i);
} - for (int i = 1; i < 10 ; ++i)
{
Console.WriteLine(i);
} - for (int i = 1; i <= 10 ; i++)
{
Console.WriteLine(i);
}
- for (int i = 0; i < 10 ; i++)
- 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");
}
-
- 01234
- 1234
An error has occurred in collection operation - 1234
An error has occurred in collection operation
Error logged for the application - 1234
An error has occurred in collection operation
An error has occurred in null reference operation
Error logged for the application
- Delegates can be instantiated by:
- Anonymous methods
- Lambda expressions
- Named methods
- All of the above
- What action needs to be performed to move a thread to the run state when suspended?
- Resume
- Interrupt
- Abort
- Suspended
- 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();
-
- Creating object of DisposeImplementation
Inside the dispose of class DisposeImplementation
Inside the finalizer of class DisposeImplementation - Creating object of DisposeImplementation
Inside the dispose of class DisposeImplementation - Runtime error in the application
- Creating object of DisposeImplementation
Inside the finalizer of class DisposeImplementation
Inside the dispose of class DisposeImplementation
- Creating object of DisposeImplementation
- 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)
-
- -7
- 1
- 7
- Run time error
- Which of these can be used to authenticate user input?
- Symmetric algorithm
- Asymmetric algorithm
- Hash values
- Digital signatures
- 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?
- List
- Stack
- Dictionary
- Queue
- Your application is running multiple worker threads. How do you make sure your application waits for all threads to complete their execution?
- Thread.Sleep()
- Thread.WaitAll()
- Thread.Join()
- None
- 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?
-
- Private protected
- Protected internal
- Protected
- Internal