Skip to main content
C# Interview Questions

C# Interview Questions for beginners – Part 2

This post is in continuation to C# interview questions for beginners – part 1 

In this post, we have compiled another list of 25 C# interview questions and their answers for beginners as well as experienced users. These questions will help you to prepare for the interviews, quick revision and provide strength to your technical skills.

Those who want to learn c# from scratch can take this course.

C# Interview Questions for beginners #csharp #interview #questions #developers Click To Tweet

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

Dispose() is called when we want for an object to release any unmanaged resources with them. On the other hand Finalize() is used for the same purpose but it doesn’t assure the garbage collection of an object.

2. What are circular references?

A circular reference is a situation in which two or more resources are interdependent on each other causes the lock condition and make the resources unusable.

3. What is generics in C#.NET?

Generics can be used to make reusable code classes to decrease the code redundancy, increase type safety, and performance. Using generics, we can create collection classes. To create a generic collection, System.Collections.Generic namespace should be used instead of classes such as ArrayList in the System.Collections namespace. Generics promotes the usage of parameterized types.

4. What is an object pool in .NET?

An object pool is a container having objects ready to be used. It tracks the object that is currently in use, a total number of objects in the pool. This reduces the overhead of creating and re-creating objects.

5. List down the commonly used types of exceptions in .Net?

ArgumentException, ArgumentNullException , ArgumentOutOfRangeException, ArithmeticException, DivideByZeroException ,OverflowException , IndexOutOfRangeException ,InvalidCastException ,InvalidOperationException , IOEndOfStreamException , NullReferenceException , OutOfMemoryException , StackOverflowException etc.

Exception handling mechnaism in .NET

6. What are Custom Exceptions?

Sometimes there are some errors that need to be handled as per user requirements. Custom exceptions are used for them and are used defined exceptions.

7. What are delegates?

Delegates are same are function pointers in C++ but the only difference is that they are type safe, unlike function pointers. Delegates are required because they can be used to write much more generic type-safe functions.

How and when to use delegates in your project?

8. How do you inherit a class from other class in C#?

Colon is used as inheritance operator in C#. Just place a colon and then the class name.

 public class DerivedClass : BaseClass

9. What is the base class in .net from which all the classes are derived from?

system.Object

10. What is the difference between method overriding and method overloading?

In method overriding, we change the method definition in the derived class that changes the method behavior. Method overloading is creating a method with the same name within the same class having different signatures.

11. What are the different ways a method can be overloaded?

Methods can be overloaded using different data types for a parameter, different order of parameters, and a different number of parameters.

12. Why can’t you specify the accessibility modifier for methods inside the interface?

In an interface, we have virtual methods that do not have method definition. All the methods are there to be overridden in the derived class. That’s why they all are public.

13. How can we set a class to be inherited, but prevent the method from being over-ridden?

Declare the class as public and make the method sealed to prevent it from being overridden.

14. What happens if the inherited interfaces have conflicting method names?

An implement is up to you as the method is inside your own class. There might be a problem when the methods from different interfaces expect different data, but as far as compiler cares you’re okay.

15. What is the difference between a Struct and a Class?

  • Structs are value-type variables and classes are reference types.
  • Classed are stored on heap whereas, structs are stored on the stack causes additional overhead but faster retrieval.
  • Structs cannot be inherited.

16. How to use nullable types in .Net?

Value types can take either their normal values or a null value. Such types are called nullable types.

Int? someID = null;
 If(someID.HasVAlue)
 {
 }

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

We can create an array with non-default values using Enumerable.Repeat.

18. What is the difference between is and as operators in c#?

is operator is used for checking the compatibility of an object with a given type and it returns the result as Boolean.

as operator is used for casting of an object to a type or a class.

19. What’s a multicast delegate?

A delegate having multiple handlers assigned to it is called the multicast delegate. Each handler is assigned to a method.

20. What are indexers in C#.NET?

Indexers are known as smart arrays in C#. It allows the instances of a class to be indexed in the same way as an array.

public int this[int index] // Indexer declaration

21. What is the difference between the “throw” and “throw ex” in .NET?

“Throw” statement preserves original error stack whereas “throw ex” have the stack trace from their throw point. It is always advised to use “throw” because it provides more accurate error information.

22. What are C# attributes and its significance?

C# provides developers a way to define declarative tags on certain entities eg. class, method etc. are known as attributes. Reflection is used to retrieve the attribute’s information.

23. How to implement singleton design pattern in C#?

In singleton pattern, a class can only have one instance and provides an access point to it globally.

 public sealed class Singleton
 {
 private static readonly Singleton _instance = new Singleton();
 }

24. What is the difference between direct cast and ctype?

DirectCast is used to convert the type of an object that requires the run-time type to be the same as the specified type in DirectCast.

Ctype is used for conversion where the conversion is defined between the expression and the type.

25. C# code is managed or unmanaged code?

C# code is managed code because Common language runtime can compile C# code to Intermediate language.

We hope that these questions help you to some extent to get through the interview.

You can also try to attempt online quiz on C#.

What do you think?

Dear Readers,
If you have any questions or suggestions please feel free to email us or put your thoughts as comments below. We would love to hear from you.

Happy Crunching!

DotNetCrunch

DotNetCrunch is a popular blog for latest Microsoft® technologies which is aimed for beginners and intermediate level professionals.