C# Questions and Answers Sampler


Here is a sample test of easy questions and answers to get your started.

What are jagged arrays?

A jagged array is an array whose elements are arrays. The elements of a jagged array can be of different dimensions and sizes. A jagged array is sometimes called an "array of arrays."

What are sealed classes?

When applied to a class, the sealed modifier prevents other classes from inheriting from it.

What are some differences between an Array and an Arraylist?

  • Arrays are strongly typed.
  • ArrayLists are not strongtly typed.
  • An array can be Single-Dimensional, Multidimensional or Jagged.
  • Arrays are fixed length that cannot be changed during runtime.
  • Arrays belong to System.Array namespace.
  • An ArrayList is similar to an array but it doesn’t have a fixed size.
  • An ArrayLists size will increase or decrease dynamically.
  • ArrayList belongs to System.Collection namespace.

Can a private virtual method be overridden?

This is a trick question. Private virtual methods are illegal in C#.

What are delegates?

A delegate is a type that represents references to methods with a particular parameter list and return type. When you instantiate a delegate, you can associate its instance with any method with a compatible signature and return type. You can invoke (or call) the method through the delegate instance. Delegates are used to pass methods as arguments to other methods. Event handlers are nothing more than methods that are invoked through delegates.

How we can create an array with non-default values?

One way to create an array with non-default values is to use the Enumerable.Repeat method.

What are indexers?

Indexers allow instances of a class or struct to be indexed just like arrays. Indexers resemble properties except that their accessors take parameters.