All Interviews

Top 50 C# Interview Questions and Answers

10/Oct/2020 | 15 minutes to read

Here is a List of essential C# Interview Questions and Answers for Freshers and mid level of Experienced Professionals. All answers for these C# questions are explained in a simple and easiest way. These questions will help you to clear your next Job interview.

C# Interview Questions

Best Answers to C# Interview Questions

These interview questions are targeted for C# Programming language. A .NET Developer should know the answers of these C# questions to clear the interview.


1. What is latest version of C# with features?

C# 1.0 released in 2002. And latest version of C# is 9.0. For more you can visit Microsoft official site Releases . There are many new features in C# 9.0. For more you can visit What's new in C# 9.0.

2. What is the difference between const, readonly and static keyword?

3. What is the difference between in, ref and out keywords?

4. What is the Inheritance? Why C# does not support multiple Inheritance?

5. What is method shadowing or method hiding in C#?

6. Differentiate Var, Object and Dynamic keywords in C#.

7. Can Virtual or Abstract member be declare private in C#?

No, It will throw compile time error.


virtual void display() // will throw error here
        {
        // Implementation

        }

8. What is Boxing and Unboxing in C# ?

9. What is Method Overloading in C#?

10. What is Value Type and Reference Type in C#?

10. What are the new features in C# 8.0?

To know more about C# 8.0 new features visit What's new in C# 8.0

11. What is Abstraction and Encapsulation in C#? How will you differentiate them?

12. What is the deference between Abstract class and Interface in C#? What is the need of these?

13. What is Polymorphism? What is static and Dynamic Polymorphism in C#?

14. What will be output of below program? Error Line will throw any error in below code?


  class A
    {
       public virtual void display()
        { Console.WriteLine("A - display method"); }
    }
    class B:A
    {
        public override void display()
        { Console.WriteLine("B - display method"); }
    }
    class Test
    {
        static void Main()
        {
            A obj = new A();
            obj.display();

            A obj1 = new B();
            obj1.display();

            B o = new B();
            o.display();
            // B ob = new A();  Error Line
            Console.ReadLine();
        }
    }

Output: 'Error Line' will throw error - Cannot implicitly convert type 'A' to 'B'. An explicit conversion exists (are you missing a cast?).
Output will be as below.
A - display method
B - display method
B - display method

16. Can Abstract class has constructor in C#? Below code will compile or not, or it will give any error in Error line 1 or 2.


class A
    {
       public virtual void display()
        {
            Console.WriteLine("A - display");
        }
        public virtual void disp()
        {
            Console.WriteLine("A - disp");
        }
    }
abstract class ab :A
    {
        public ab()
        { }
        public abstract override void display(); Error Line 1

        public sealed override void disp()  Error Line 2
        {
            Console.WriteLine("disp is sealed now.");
        }
    }

Solution: Abstract class can contain the constructor. Constructor is used to instantiate the class instance members in C#.
Above code will compile successfully. In C#, we can add Abstract and Sealed keywords with the override keyword.

17. What is volatile keyword in C#?

18. What is the use of sealed keyword in C#?

19. Explain string interpolation in C#.

20. What is the difference between abstract and virtual keywords?

20. What are the new features in C# 7.0?

To know more about C# 7.0 new features visit What's new in C# 7.3

21. What is Covariance and Contravariance in C#?

Fore more Covariance and Contravariance in C#

22. What will be output of following program? or will throw any error?


    public void display()

    {
    int x = 0;
    int y = 10;
    try
    {
    int z = y / x;
    }
    catch (Exception)
    {
    throw;
    }
    catch (DivideByZeroException)
    {
    throw;
    }
    finally
    {
    }

    }

23. What points (related to try, catch and finally) you should keep in mind while implementing exception handling in C#?

24. What is Generics in C#? What are the benefits of Generics?

25. What is IDisposable Interface in C#? How to implement dispose method?

26. Explain Dispose Pattern in C#.

27. How does Garbage Collection work in C#? Explain Generations.

28. What is using statement in C#?

29. What is Finalizers in C#? Explain SupressFinalize() method.

30. What will be output of below code?


    int a = 0;
    try
    {
    int x = 4;
    int y ;
    try
    {
    y = x / a;
    }
    catch (Exception e)
    {
    Console.WriteLine("inner ex");
    //throw;   // Line 1
    //throw e;   // Line 2
    //throw new Exception("divide by 0");  // Line 3
    }

    }
    catch (Exception ex)
    {
    Console.WriteLine("outer ex");
    throw ex;
    }

31. What is Equals method?

32. What is the difference between Equality operator == and Equals() method in C#?

33. What is the use of new keyword rather than creating new object in C#?

34. What is the extension methods in C#?

35. Explain Partial class and methods.

36. In how many ways can you pass parameters in C#?

37. What is the difference between EXE and DLL file?

38. What is DLL hell Problem?

39. What is Asynchronous Programming?

40. What is async and await in C#?

44. What are the new features in C# 6.0?

To know more about C# 6.0 new features visit What's new in C# 6.0

Some General Interview Questions for C#

1. How much will you rate your self in C#?

When you attend an interview, Interviewer may ask you to rate your self in specific Technology like C#, So It's depend on your knowledge and work experience in C#.

2. What challenges did you face while working on C#?

This question may be specific to your technology and completely depends on your past work experience. So you need to just explain the challenges you faced related to C# in your Project.

3. What was your role in last Project related to C#?

It's based on your role and responsibilities assigned to you and what functionality you implemented using C# in your project. This question is generally asked in every interview.

4. How much experience do you have in C#?

Here you can tell about your overall work experience on C#.

5. Have you done any C# Certification or Training?

It's depend on candidate like you have done any C# training or certification. Certifications or trainings are not essential but good to have.

Conclusion

We have covered some frequently asked C# Interview Questions and Answers to help you for your Interview. All these Essential C# Interview Questions are targeted for mid level of experienced Professionals and freshers.
While attending any C# Interview if you face any difficulty to answer any question please write to us at info@qfles.com. Our IT Expert team will find the best answer and will update on portal. In case if we find any new C# questions, we will update the same here.

Check it