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
  }
}

What is the difference between CopyTo and Clone methods?

  • CopyTo() method copies the contents of an existing array into another array
  • Clone() method creates a new Array and copies all the elements into new Array
  • Both the methods perform a shallow copy of the array elements

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