C# .NET interview questions

C# .NET quiz questions

  • 1.

    What are the types of delegates in C#?

    Answer:

    Below are the uses of delegates in C# -

    • Single Delegate
    • Multicast Delegate
    • Generic Delegate
    View
  • 2.

    What you mean by delegate in C#?

    Answer:

    Delegates are type safe pointers unlike function pointers as in C++. Delegate is used to represent the reference of the methods of some return type and parameters.

    View
  • 3.

    Explain object pool in C#?

    Answer:

    Object pool is used to track the objects which are being used in the code. So object pool reduces the object creation overhead.

    View
  • 4.

    Explain Generics in C#?

    Answer:

    Generics in c# is used to make the code reusable and which intern decreases the code redundancy and increases the performance and type safety. 
    Namespace – “System.Collections.Generic” is available in C# and this should be used over “System.Collections” types.

    View
  • 5.

    List out some of the exceptions in C#?

    Answer:

    Below are some of the exceptions in C# -

    • NullReferenceException
    • ArgumentNullException
    • DivideByZeroException
    • IndexOutOfRangeException
    • InvalidOperationException
    • StackOverflowException etc.
    View
  • 6.

    Explain circular reference in C#?

    Answer:

    This is a situation where in, multiple resources are dependent on each other and this causes a lock condition and this makes the resource to be unused.

    View
  • 7.

    How we can sort the array elements in descending order in C#?

    Answer:

    “Sort()” method is used with “Reverse()” to sort the array in descending order.

    View
  • 8.

    What is the difference between methods – “System.Array.Clone()” and “System.Array.CopyTo()” in C#?

    Answer:

    • “CopyTo()” method can be used to copy the elements of one array to other. 
    • “Clone()” method is used to create a new array to contain all the elements which are in the original array.
    View
  • 9.

    What is the difference between “StringBuilder” and “String” in C#?

    Answer:

    • StringBuilder is mutable, which means once object for stringbuilder is created, it later be modified either using Append, Remove or Replace.
    • String is immutable and it means we cannot modify the string object and will always create new object in memory of string type.
    View
  • 10.

    Explain String Builder class in C#?

    Answer:

    This will represent the mutable string of characters and this class cannot be inherited. It allows us to Insert, Remove, Append and Replace the characters. “ToString()” method can be used for the final string obtained from StringBuilder. For example,

    StringBuilder TestBuilder = new StringBuilder("Hello");
    TestBuilder.Remove(2, 3); // result - "He"
    TestBuilder.Insert(2, "lp"); // result - "Help"
    TestBuilder.Replace('l', 'a'); // result - "Heap"
    View
  • 11.

    What you mean by inner exception in C#?

    Answer:

    Inner exception is a property of exception class which will give you a brief insight of the exception i.e, parent exception and child exception details.

    View
  • 12.

    In try block if we add return statement whether finally block is executed in C#?

    Answer:

    Yes. Finally block will still be executed in presence of return statement in try block.

    View
  • 13.

    Explain access modifier – “protected internal” in C#?

    Answer:

    “protected internal” can be accessed in the same assembly and the child classes can also access these methods.

    View
  • 14.

    Can we override private virtual method in C#?

    Answer:

    No. We can’t override private virtual methods as it is not accessible outside the class.

    View
  • 15.

    What are reference types in C#?

    Answer:

    Below are the list of reference types in C# -

    • class
    • string
    • interface
    • object
    View
  • 16.

    What are value types in C#?

    Answer:

    Below are the list of value types in C# -

    • decimal
    • int
    • byte
    • enum
    • double
    • long
    • float
    View
  • 17.

    Can we use “this” inside a static method in C#?

    Answer:

    No, we can't

    View
  • 18.

    Explain Jagged Arrays in C#?

    Answer:

    If the elements of an array is an array then it’s called as jagged array. The elements can be of different sizes and dimensions.

    View
  • 19.

    What is the difference between “out” and “ref” parameters in C#?

    Answer:

    “out” parameter can be passed to a method and it need not be initialized where as “ref” parameter has to be initialized before it is used.

    View
  • 20.

    What are the differences between static, public and void in C#?

    Answer:

    • Static classes/methods/variables are accessible throughout the application without creating instance. Compiler will store the method address as an entry point. 
    • Public methods or variables are accessible throughout the application. 
    • Void is used for the methods to indicate it will not return any value.
    View

© 2017 QuizBucket.org