I prepared a basic list of popular interview questions for .NET developers. Currently, there are 50+ questions. Most of these questions apply to junior developers. As far as possible, I will add questions for middle and senior developers.
1. What are the principles of object-oriented programming?
- Abstraction – separating the idea from the implementation
- Polymorphism – implementing an idea in different ways
- Inheritance – code reuse
- Encapsulation – private methods
2. What is SOLID?
SOLID is an acronym for the first five principles of object-oriented programming, formulated by Robert S. Martin:
- Single responsibility – an object and a method should only do one thing, as opposed to the God-object antipattern
- Open closed principle – adding new features should not require changing existing code
- Liskov substitution – use the base class without knowing about the implementation of the successor
- Interface segregation principle – don’t bloat interfaces
- Dependency inversion principle – first interfaces, then implementation, but not vice versa
3. What is .NET Framework
.Net Framework is a software development platform developed by Microsoft for building and running Windows applications. The .Net framework consists of developer tools, programming languages, and libraries to build desktop and web applications. It is also used to build websites, web services, and games.
4. What is Common Language Runtime (CLR)?
The CLR is a component of the .NET Framework whose main task is to manage the interpretation and execution of IL code. The CLR is responsible for isolating application memory, type checking, code safety, and converting IL to native code.
5. What is Intermediate Language(IL)?
IL (Intermediate Language) – code containing a set of platform-independent instructions. In other words, after compiling the source code, it is not converted into code for a particular platform, but into intermediate IL code.
6. What is CLS(Common Language Specification)?
CLS is a set of rules by which developers achieve conflict-free operation in all .NET languages.
7. What is Managed Code?
Managed code is code that runs in the CLR. Contains metadata that provides runtime information about types, members, and references used in code.
8. What is Assembly?
Assembly – one or more files containing a logical set of functionality (code and other data associated with the code). There are static assemblies, which are stored on disk, and dynamic assemblies, which are created during program execution. An assembly is the basic block of an application, all resources related to it are available either only inside this block, or are exported outside. At runtime, the assembly sets the name scope and enforces it.
9. What are private and shared Assemblies?
There are two types of assemblies – private, which uses only the application itself, and shared, used by a set of applications. With private builds, the application is isolated from the external influence of programs and the operating system, there is no need to worry about the uniqueness of names in the global namespace. To make an assembly shared, it must be assembled in a special way and given a strong encrypted name.
10. What is Assembly Manifest
An assembly manifest is an internal part of an assembly that allows it to be self-describing. The assembly manifest allows you to identify the assembly, specifies the files that are included in the assembly implementation, describes the types and resources used in the assembly, specifies dependencies on other assemblies, and the set of access rights that the assembly needs to work correctly. This information is used at runtime to resolve references, validate versions, and check the integrity of loaded assemblies.
11. What is the difference between namespace and assembly concepts?
The namespace is a logical convention used at design time, while assembly sets the scope of the name at run time.
12. What is the difference between Value Type and Reference Type?
The value Type is on the stack and the reference type is on the heap.
13. When is an object garbage collected?
An object is garbage collected when it is no longer referenced.
14. What is Code Access Security (CAS)?
CAS is a security technology that allows you to set a limit on the execution of managed code. In this way, you can define permissions and set access rights to computer resources.
15. What is Attribute?
An attribute is a universal means of linking data with types. They allow you to add any textual information about classes, properties, methods, etc. Attributes are stored with metadata and can be retrieved when the program is executed.
16. What is the difference between Finalize and Dispose?
Dispose provides explicit control over the resources used by the object, while Finalize is implicit, used by the garbage collector.
17. What is Boxing and Unboxing?
Boxing allows you to convert a value type to a reference type. When packing a value type object, the following actions occur:
- Memory is allocated on the managed heap.
- The fields of the value type are copied into the memory that was allocated on the heap.
- The address of the object is returned.
Boxing and Unboxing reduces the performance of the application both in terms of slowdown and additional memory consumption, so you should try to minimize the creation of code in which the operations of boxing/unboxing occur.
18. What is Global Assembly Cache(GAC)?
GAC is the global assembly cache. It stores shared assemblies. This is usually C:\Windows\Assembly\GAC. This directory has a certain structure, which stores subdirectories whose names are generated according to a certain algorithm. Only strongly named assemblies can be placed in the GAC. To place an assembly in the GAC, the special tool GACUtil.exe is used, which knows the entire internal structure of the GAC and can generate subdirectory names properly. Registering assemblies in the GAC is necessary in order to avoid assembly name conflicts. Let’s take an example: two companies released an assembly and called it the same name Calculus. If we copy this assembly to a directory that already contains an assembly with the same name, then we will overwrite an assembly that may have previously been used by some application. This application with the new assembly will no longer be able to work. The solution to this problem is to register these two assemblies in the GAC, in which a separate directory will be created for each.
19. What types can be used in a foreach loop?
Arrays, collections. Classes that implement the System.Collections.IEnumerable interface.
20. What is the difference between a class and a struct?
At the first glance structures are very similar to classes, but there is a fundamental difference, which is that a class is a reference type, and structures are a value type. The more you use structs instead of small classes, the less memory intensive it will be. Just like classes, structs can have fields, methods, and constructors.
21. What does the Virtual modifier mean?
When inheriting a class. This method can be overridden in derived classes using the override keyword.
22. What is Event?
The Event is a user or program action that generates notifications to the application to which it must respond. The user actions can be mouse movements, keypress, and so on. Program events could be finishing some IO tasks, component initialization, etc.
23. Can a class implement two interfaces that have the same methods declared? How?
Yes. For this purpose, you need to specify an interface name within the method name. Here is an example:
public class MyMultiGame : IFootballGame, IVolleyballGame { Object IFootballGame.Play() { ... } Object IVolleyballGame.Play() { ... } }
24. Does C# support multiple inheritance?
C# supports multiple inheritance in the form of inheritance from a class and multiple interfaces, or just from multiple interfaces. But it does not support inheritance from multiple classes.
25. Who can access protected variables at the class level?
Any derived class.
26. Are variables inherited with the private modifier?
Yes, but they are not available.
27. Describe the “protected internal” modifier
Members with this modifier are available to classes that are in the same assembly and inherit from this class.
28. What is the name of the .NET class that all classes inherit from?
System.Object.
29. What does the term immutable mean?
This means that the data stored in the variable cannot be changed. In doing so, note that the value of a variable can be changed – by not using old data that can be changed. The original data remains in memory, and new values are created again in a new memory area. An example is the String type.
30. What’s the difference between the System.String and System.Text.StringBuilder classes?
The data stored in the System.String class is immutable. The System.StringBuilder class was designed to allow many operations to be performed on a mutable string. That is, with each operation on an object of the System.String class, data is transferred to a new memory area, which affects the performance of the program.
31. What is the advantage of using the System.Text.StringBuilder class over System.String?
The StringBuilder class is more efficient when dealing with a large number of strings. Objects of the System.String class are immutable, so each time the string changes, a new object is created in memory.
32. Explain the difference between System.Array.CopyTo() and System.Array.Clone()?
The first operation performs a deep copy of the array, and the second one shallow. Shallow copying(Clone) of an array only copies the elements of an Array object, whether they are reference types or value types. Objects referenced by reference types are not copied. The references in the new Array object point to the same objects as the references in the original Array. A deep copy(Copy) copies both the elements of the Array class and the objects they refer to explicitly or implicitly.
33.How to sort array elements in descending order?
You need to call the Sort() method and then the Reverse() method.
34. As, Is – what is it, how is it applied?
throw re-throws the exception that was encountered and saves the stack trace (path to the source of the exception).
throw ex throws the same exception, but resets the stack trace to the method where throw ex is done.
35. How does return work in try-catch-finally?
The algorithm is the next:
- The code before the return statement is executed
- The expression in return is evaluated
- The finally block is executed
- Returns the result calculated in step 2
36. Is it possible to forbid inheritance from your own class?
Yes. The keyword “sealed” is used for this.
37. Is it possible to allow class inheritance but prevent method overriding?
Yes. Specify the class as public and the method as sealed.
38. What is an abstract class?
This is a class whose object cannot be instantiated. Such a class must have a descendant class with the implementation of abstract methods. An abstract class is actually a blueprint of a normal class with no implementation.
39. When are you required to declare a class abstract?
Abstract classes are needed in order to isolate common functionality from several classes into a separate class. From this separate class, you can then inherit either just the signature of the functional or together with the implementation. A class must be declared abstract when it contains abstract members.
40. What is Interface?
Interfaces, like classes, define a set of properties, methods, and events. But, unlike classes, they do not contain their implementation. Interfaces are implemented by classes and are defined as independent entities.
41. Why can’t you specify a visibility modifier for interface methods?
Because all of them must have the public modifier, which is set by default.
42. Is it possible to inherit from multiple interfaces?
Yes.
43. What is the difference between an interface and an abstract class?
In an interface, all methods (properties, etc.) are abstract and have no implementation. In an abstract class, some methods can be implemented. In an interface, members cannot have a visibility modifier (they are all public by default), but in an abstract class, members can have a visibility modifier.
44. What is the difference between abstract and virtual methods?
A virtual method has an implementation and can. overridden in a derived class. An abstract method has no implementation, only a description of the method that should be. implemented in derived classes.
45. What is the using(…){…} construct in .NET for? What about IDisposable?
The value of Using is directly related to the IDisposable interface. The IDisposable interface gives us the ability to quickly release shared resources without relying on an automatic garbage collector. The Using construct allows you to call the Dispose method automatically as soon as the desired object leaves the Using block.
46. What is a “satellite assembly”?
Assemblies marked with specific locales are called satellite assemblies.
47. What is difference between Const vs Readonly?
The const value is substituted during the compilation. And you can set it only before compilation. The readonly value can only be set before compilation or in the constructor.
48. What is the difference between an abstract class and an interface?
The main difference is that an abstract class can contain methods (not abstract) that have an implementation. in turn, interfaces contain only contracts.
49. What is the difference between abstract and virtual methods?
A virtual method is a method that MAY be overridden in a derived class. Such a method can have a standard implementation in the base class.
An abstract method is a method that MUST be implemented in a derived class. At the same time, an abstract method cannot have its implementation in the base class (the body is empty), unlike a virtual one.
50. What are the differences between a Class and a Struct?
Class: reference type, Supports Inheritance, Members are private by default, good for larger complex objects
Struct: value type, Does not support inheritance, Members are public by default, good for Small isolated models
51. What types of programming patterns are there?
Each programming pattern can be attributed to one of the following types:
- Generators (example: abstract factory)
- Structural (example: decorator)
- Behavioral (example: chain of responsibilities)
52. How would you Design Logger To File and Console?
Read the full answer in my separate article – Creating Logger To File and Console – C# Popular Interview Question
53. What is the Difference between Property and Field?
Read the full answer with examples in my article – Difference between Field and Property in C#
54. Difference Between Static Class and Singleton
A singleton can extend classes and implement interfaces, while a static class cannot. A singleton can be initialized lazily or asynchronously while a static class is generally initialized when it is first loaded. Check my article with the full list of differences between static classes and singleton pattern.
55. What Difference Between == and Equals operators in C#?
The equality operator == checks whether two operands are equal or not, and the Object.Equals() method checks whether the two object instances are equal or not.