Explain async and await

  • async and await keywords are used for asynchronous operations
  • awaiting a process puts in a separate task and returns the reference to that task.
  • Once complete the runtime makes sure that the process starts execution back from where the await process occurs
  • A method in which an await keyword is used should be marked async
public async Task<string> DoSomething() {
    var res = await httpClient.GetAsync("SOME_GET_API");
    return await res.Content.ReadAsStringAsync();
}

What is the difference between Finalize() and Dispose() methods?

  • Object.Finalize() method releases unmanaged resources but don't assure garbage collection. It is called before the Garbage Collector reclaims the memory. It is also called as a destructor, which is complementary to the constructor, where memory allocation happens.
public class MyClass {
  ~MyClass() {
    // any custom release operations
  }
}

How can I call the base implementation of an overridden virtual method?

Using the C# language constructs, you cannot explicitly call the base function from outside the scope of A or B. If you really need to do that, then there is a flaw in your design - i.e. that function shouldn't be virtual to begin with, or part of the base function should be extracted to a separate non-virtual function.

class A
{
  virtual void X() { Console.WriteLine("x"); }
}

class B : A
{
  override void X() { Console.WriteLine("y"); }
}

class Program
{
  static void Main()
  {
    A b = new B();
    // Call A.X somehow, not B.X...
  }
}

What is LINQ?

  • LINQ stands for Language Integrated Queries
  • LINQ library offers a set of features to perform data operations irrespective of data sources
  • It can be used to bridge between objects and data

What are the differences between an Array and an ArrayList?

Arrays:

  • An Array uses a vector array for storing data
  • It can store only a single data type
  • Length of the Array is fixed and can't be increased dynamically
  • since the type is specified during declaration, there's no need for type casting the values

ArrayList:

  • An ArrayList is of variable length which can accommodate any number of elements
  • It uses a LinkedList for storing data
  • It is a dynamic type which can store any datatype
  • since it can store any type of data, it requires type casting while accessing the values

What are Jagged Arrays?

An array of arrays is called a Jagged Array. Each individual array within the Jagged Array can be of variable length.

var jaggedArray = new int[10][];
jaggedArray[0] = new int[5];
jaggedArray[1] = new int[10];
jaggedArray[2] = new int[2];

What is meant by Boxing and Unboxing?

The method of converting a value type into a reference type is called as BOXING

int a = 15;
string myString = a.ToString();

The conversion of a reference type into a value type is called as UNBOXING

string str = "15";
int val = int.parse(str);