interview-questions

. NET Interview questions

2. What is difference between . NET Core and . NET Framework?

.NET Core

.NET Framework

3. What is CoreCLI?

4. What is JIT compiler?

5. What is the difference between AppDomain, Assembly, Process, and a Thread?

AppDomain

Assembly

Process

Thread

6. What is an Object and a Class?

Class

Object

7. What are the fundamental OOP concepts? (The 4 pillars)

Inheritance

Polymorphism

Abstraction

Encapsulation

8. What is Managed and Unmanaged code?

Managed code

Unmanaged code

9. What is an Interface?

10. What are the different types of classes in C#?

What is a class

Abstract classes

Partial classes

Sealed classes

Static classes

11. Explain code compilation in CSharp

12. What are the differences between a Class and a Struct?

Classes

Structs

Both struct and class

13. What is the difference between the Virtual method and the Abstract method?

14. What is a Namespaces in C#?

15. What is using statement in C#?

16. How is Exception Handling implemented in C#?

17. What are C# I/O classes? What are the commonly used I/O classes?

Most common I/O classes

18. What is a Destructor in C#?

19. What are Boxing and Unboxing?

Boxing

    int number = 7;
    object obj = i;

Unboxing

    obj = 123;
    number = (int)obj;

20. What is the difference between Continue and Break Statement?

21. What is the difference between finally and finalize block?

Finally

Finalize

22. What is an Array?

     int[] singleArray = new int[5];
     int[,] multiArray = new int[2, 3];
     int[,] multiArray2 = new int { {1, 2, 3 }, {7, 8, 9}};
     int[] [] jaggedArray = new int [6][];
     jaggedArray[0] = new int[4]{1, 2, 3, 4, 5};

23. What is a Jagged Array?

    int[] [] jaggedArray = new int [3] [];
    jaggedArray[0] = new int[5];
    jaggedArray[1] = new int[4];
    jaggedArray[2] = new int[2];

24. What is a String?

25. What are Regular expressions?

    string pattern = @"^[A-Z][a-zA-Z]*$";
    string firstName = "Victor";
    if(Regex.IsMatch(firstName, pattern){
        Console.WriteLine("It's a match!");
    }

26. What is Parsing? What is Casting?

Parsing

Casting

27. What is a Delegate?

    public static void WriteToScreen(string str) {
        Console.WriteLine("The String is: {0}", str);
    }
    public delegate void printString(string s); // declaration
    printString firstString = new printString(WriteToScreen); // create delegate object

28. What are Events?

    // declare a delegate type for the event
    public delegate string BoilerLogHandler(string str);

    class EventProgram {
        // declare the event
        event MyDel MyEvent;

        public EventProgram() {
            this.MyEvent += new MyDel(this.WelcomeUser);
        }
        public string WelcomeUser(string username) {
            return "Welcome " + username;
        }
        static void Main(string[] args) {
            EventProgram obj1 = new EventProgram();
            string result = obj1.MyEvent("To Events");
            Console.WriteLine(result);
        }
    }

29. What is Reflection in C#?

30. What are generics? What is a Generic Class?

    public class GenericList<T>
    {
    public void Add(T input) { }
    }

31. What are async and await ?

Asynchronous programming

Async & await

32. What is a Deadlock ?

33. What is a Race Condition?

34. What is Serialization?

35. Can multiple catch blocks be executed?

36. What are the different access levels?

Accessibility levels for members are defined by access modifiers

Default accessibility

37. What is the difference between static methods and instance methods?

Static methods

Instance methods

38. What is a constructor?

39. What is the difference between ref & out parameters?

Ref

Out

40. Can we use this command within a static method?

41. What is the difference between constants and read-only?

Constant

Read-only

42. What are value types and reference types?

Value types

Reference types

43. What is method overloading?

44. Can a private virtual method can be overridden?

45. How do you inherit a class into other class in C#? Can you inherit multiple classes? What about interfaces?

46. What is the base class in . NET from which all the classes are derived from?

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

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

49. How to use nullable types in . NET?

     double? pi = null; 

50. What is difference between “is” and “as” operators in c#?

Is operator

As operator

51. What are indexers?

    class SampleCollection<T>
    {
    // Declare an array to store the data elements.
        private T[] arr = new T[100];

        // Define the indexer to allow client code to use [] notation.
        public T this[int i]
        {
            get { return arr[i]; }
            set { arr[i] = value; }
        }
    }

    class Program
    {
        static void Main()
        {
            var stringCollection = new SampleCollection<string>();
            stringCollection[0] = "Hello, World";
            Console.WriteLine(stringCollection[0]);
        }
    }

52. What is difference between the throw and throw ex ?

Throw

Throw ex

53. What are C# attributes and its significance?

54. How to implement a singleton design pattern in C#? And what about a thread safe singleton?

Singleton pattern

Non-thread safe (bad example)

public sealed class Singleton
    {
    private static Singleton instance=null;

    private Singleton()
    {
    }

    public static Singleton Instance
    {
        get
        {
            if (instance==null)
            {
                instance = new Singleton();
            }
            return instance;
        }
    }
}

Simple thread safety

public sealed class Singleton
{
    private static Singleton instance = null;
    private static readonly object padlock = new object();

    Singleton()
    {
    }

    public static Singleton Instance
    {
        get
        {
            lock (padlock)
            {
                if (instance == null)
                {
                    instance = new Singleton();
                }
                return instance;
            }
        }
    }
}

55. Explain Finalize vs Dispose usage?

Finalizers

Dispose