In this blog, I have collected the most common interview questions and answers based on my personal experience. Below are questions asked for the Senior Dot Net developer role.
1. What is Middleware?
Middleware is software used to communicate between 2 systems. Middleware also implements code re-usability features.
RPC, CORBA, and Web Services are a few commonly used Middleware technologies.
Middleware is similar to a joint in a water plumbing pipe, which connects 2 pipes to pass the water.
2. Web Server vs Application Server
A web Server is a server which is used to serve web-related files over HTTP protocols.
A web server contains HTML, ASPX and any static files like CSS, Scripts, and Images.
The application Server executes the business logic of an application and handles any protocols including HTTP.
IIS is a Web Server
Apache is a web server
Apache Tomcat is an Application server.
3. What is SOA?
Service Oriented Architecture (SOA) is a style to design software system where 2 or more component communicates with each other over a network through a defined protocol.
Advantages of SOA architecture.
Loosely Couple – A component in SOA architecture must be loosely coupled. One service does not require knowing the technical and platform details of another service.
Reusable Component – In SOA all components are reusable.
Read more about Service Oriented Architecture.
4. What is a design pattern?
Design pattern solves common code optimization and re-usability issue.
Design patterns provide efficient and reusable solutions in software development.
There are several design patterns available, each pattern has its own significance based on project structure and/or business need.
Some of the commonly used Design Patterns –
Abstract Factory
Factory Method
Facade
Singleton
5. 3-Tier vs N-Tier Architecture
The 3-Tier architecture is an architecture in which the User interface, Business logic, and Data Access layer is written as independent modules.
The letter N in N-Tier is just a number.
In N-tier architecture, you have N number of layers of components.
3-Tier architecture could be N-Tier architecture if N=3.
C# Interview Questions and Answers
C# 6.0 new features
6. Verification vs Validation
Verification is to check whether the final product meets the specification. The verification process generally occurs before validation.
Validation is to check whether the final product meets the end user’s expectations. Validation occurs post-verification.
7. Authentication vs Authorization
Authentication is the process to check if a user credential is correct or not.
Authorization occurs post Authentication. Authorization is the process to check what access has been given to an authenticated user. Mainly Authorization is related to the Role.
8. What is a framework?
A framework is a building block on which a developer develops an application by using a supported programming language.
We can define Framework in another way –
A framework contains a set of common codes which provides generic functionality.
9. DLL vs EXE
DLL stands for Dynamic Link Library. We can call DLL libraries on run-time and not on compile time.
Exe is the extension of Executable files. An EXE file can run independently. But A DLL file generally used to support other application.
An EXE file will have an entry point, but a DLL file will not have an entry point.
10. What is High-Level Design?
High-Level Design (HLD) explains depict the flow of software application. Data Flow, Flow Charts are covered under HLD.
11. HLD vs LLD
HLD includes the overall architecture of an application, it includes the Data Flow diagram, Flow Chart.
LLD or Low-Level Design is created based on HLD. Low Level Design document describes the class diagrams.
LLD shows the modules which help a developer to write code and is basically the detail explanation of HLD.
12. What is Virtual Keyword in C#?
Virtual or abstract members cannot be private.
Error in below code:
public class Class1 { private virtual void Method() //method cannot be private as virtual method must be accessible in other class to override { Console.Write("Hello"); } }
Below code will give an error:
Can not change access modifiers when overriding inherited member
See below code:
public class Program:Class1 { static void Main(string[] args) { } public override void Method()//Access modifier is changed from protected to public { base.Method(); } } public class Class1 { protected virtual void Method() //Here the virtual method is protected { Console.Write("Hello"); } }
13. Code optimization Tools
Code optimization tools evaluate your code and suggest you to what could be better, if possible.
There are numerous tools available with Visual Studio, one of them is Re-sharper that is widely used.
These tools suggest you on below –
Naming conventions
Object decomposition
Proper Comments
14. What is a Monolithic Application?
A monolithic application is a self-contained program in which user interface and data access code are written into a single program.
Monolithic applications are difficult to maintain as it gets complex with time.
15. Primitive data type vs non-primitive data type
A primitive data type is predefined by the system for eg- byte, short, int, float, double long etc.
A non-primitive data type is a user-defined for eg – class, struct, interface etc.
16. SOAP vs Restful Service
Web service is a way to communicate between 2 machines via HTTP, those 2 machines can be on a different platform.
Web services are of 2 types. SOAP and REST.
SOAP – SOAP stands for Simple Object Access Protocol. REST is lighter service compare to SOAP web service. SOAP is an XML based web service.
Representation State Transfer – So, what does that mean? Simply, REST is just an architectural style to build and loosely couple 2 or more systems.
In REST, a client sends a request and server responds to that request. This response is the representation of a resource which can be in HTML, XML, JSON, Plain Text format.
Know more about SOAP and REST
17. Differences between Managed and Unmanaged Code
Managed code uses CLR to manage object allocation/deallocation.
Any code written in .NET Framework is managed code. The code, which is developed outside .NET Framework is called as unmanaged code.
18. Differences between Boxing and Unboxing
Boxing: Boxing refers to the process of moving from a value type to reference type.
Un-Boxing: Un-Boxing refers to the process of moving from a reference type to value type.
19. Differences between Constant, Static and Read-only
A read-only field can be initialized either at the time of declaration or within the constructor of the same class. Therefore, readonly fields can be used for run-time constants.
Constant
Constant fields or local variables must be assigned a value at the time of declaration and after that, they cannot be modified. By default constant are static, hence you cannot define a constant type as static.
Static
The static keyword is used to specify a static member, which means static members are common to all the objects and they do not tied to a specific object.
Read more about Constant vs Read only vs Static
20. What is a garbage collection?
Garbage collection is a technique in .Net framework to manage unused objects and make the space available for other objects.
Garbage collector manages object allocation and claims the memory.
21. What is a delegate?
A delegate is a reference type and refers method.
Declaration of Delegate
public delegate void MyDelegate();
C# code without delegate:
public class Program { static void Main(string[] args) { Program.Add(20, 10); } public static void Add(int a, int b) { Console.WriteLine(a + b); } }
C# code with delegate:
public delegate void MyDelegate(int a, int b); public class Program { static void Main(string[] args) { MyDelegate del = new MyDelegate(Add); //Holding the reference of Add method del(10,20); } public static void Add(int a, int b) { Console.WriteLine(a + b); } }
22. IEnumerable vs IEnumerator
These are the interfaces which help to loop through the collection. Also, IEnumerable uses IEnumerator internally.
IEnumerable and IEnumerator comes under System.Collection namespace.
List<string> productList = new List<string>(); productList.Add("TV"); productList.Add("Mobile"); productList.Add("Laptop"); productList.Add("Audio system"); productList.Add("Tablet"); IEnumerable<string> enumlist = (IEnumerable<string>)productList; foreach (string p in enumlist) { Console.WriteLine(p); } IEnumerator<string> enumaratorlist = productList.GetEnumerator(); while (enumaratorlist.MoveNext()) { Console.WriteLine(enumaratorlist.Current); }
23. Differences between Two dimensional vs Multidimensional Array
2-dimensional arrays are indexed by two subscripts. One is a row and another one is a column.
int [,] array = new int[2,2] array[0, 0] = 1; Console.WriteLine(array[0, 0]);
The Multi-Dimensional Array in C# contains more than one rows to store the data. It is also known as the Rectangular Array in C#.
24. Differences between Interface and Abstract Class
Interface | Abstract Class |
If we don’t know about implementation then go for Interface | If we know about implementation then go for Abstract class |
Every method in an Interface is public by default. | In Abstract class every method need not to be public class. Abstract class may contain Abstract or non-abstract (concrete) methods. |
We can’t use method with access modifier like public, private, protected | Abstract class has no such restrictions. |
An interface cannot contains constructor | Abstract class can contains constructor |
25. What is a Nullable Type?
A nullable type is a special data type in C# which accepts normal values as well as Null.
For eg – Nullable<bool> can take true, false or null.
26. What is Cross Page Posting?
Generally ASP.Net submit forms to the same page. If you are creating multi page form to save information, in this case you are submitting the form to a different page.
We use PreviouspPage property to check if the page is accessed as cross page postback.
27. What is Impersonation in ASP.Net?
Impersonation is the process of executing a code in the context of another user identity. ASP.Net Impersonation is disabled by default. If Impersonation is enabled in an ASP.Net application, the application runs in the context of identity whose access token IIS passes to ASP.Net. The token can be logged in windows user or anonymous user such as IUSR_MachineName identity.
28. What is Page Tracing?
Page tracing in an ASP.Net web application allows you to view diagnostic information about a request for a web page. Tracing enables you to follow page execution paths.
29. Differences between object, var, dynamic keywords
object is the base class for all classes.
var keyword was introduced in version 3.0 of C#. var keyword is a compile time feature so it is checked at compile time.
var keyword does not require boxing and unboxing.
dynamic keyword is checked at run time. It can store any type of data.
C# Interview Questions and Answers
C# 6.0 new features
30. What is Dependency Injection?
Dependency Injection is a design approach, which helps to create loosely coupled code. In another way, we can say that Dependency Injection is used to remove dependency between two classes and helps to create independent classes.
Read more about Dependency Injection
31. Class vs Struct
A class is a reference type, Struct is a value type.
An object of the class holds the reference to the memory.
A struct does not support inheritance but class support.
A struct can not have default constructor but a class has.
Read more about Class vs Struct
32. What is HTTP Handler?
An ASP.Net HTTP handler is the process that runs in response to a request that is made to an
ASP.Net web application.
ASP.Net page handler is the most common HTTP handler to handle .ASPX file.
We may create custom HTTP handler, for eg If you want your application to serve images, then you may write custom HTTP handler.
Suppose you want to handle requests for .abcx file, then you have to create custom HTTP handler.
public class ABCxHandler :IHttpHandler { public bool IsReusable { get { return false; } } public void ProcessRequest(HttpContext context) { } }
Add below line to web.config file –
<httpHandlers> <add verb="*" path="*.abcx" type="ABCxHandler"/> </httpHandlers>
33. What is HTTP module?
An HTTP module is an assembly that is called every request sent to the application. HTTP module passes through all the modules in the pipeline of the request.
For eg – Authentication, Exception Logging etc.
34. What is Lambda Expression?
Lambda expressions are anonymous functions, it contains set of operators and uses lambda operator i.e. => (Read “goes to”)
Operator of Lamba divides the expressions into 2 parts.
Left part is input parameter and right one is called lambda body.
Format of Lambda expression
input parameters => Lambda statements
public static void Main(string[] args) { List<int> numberList = new List<int>() { 2,3,4,6,7,8,9 }; List<int> evenNum = numberList.FindAll(i => (i % 2) == 0); foreach (var num in evenNum) { Console.Write("{0} is an even numbern", num); } Console.Read(); }
35. What is IQueryable?
IQueryable exists in System.Linq namespace. It can move in forward direction and not in backward direction. IQueryable is good if you have huge data to query.
using (DbEntities dbContext = new DbEntities()) { IQueryable<Users> iQuery = null; iQuery = (from u in dbContext.Users where u.UserId == 1 select u); }
36. Array vs ArrayList
An array is of fixed length.
ArrayList has no fixed length.
An array is strongly typed.
ArrayList is not strongly typed.
37. await and async keyword
await and the async keyword is used to mark a method in case you are working with a long-running task.
await cannot be used without async.
You will get below error if you will mark a task with await keyword and you are not using async keyword as method modifier.
The ‘await’ operator can only be used within an async method. Consider marking this method with the ‘async’ modifier and changing its return type to ‘Task’
static void Main(string[] args) { Call1(); Call2(); Console.ReadKey(); } public static async Task Call1() { await Task.Run(() => { for (int i = 0; i < 50; i++) { Console.WriteLine("Calling i " + i); } }); } public static void Call2() { for (int j = 0; j < 25; j++) { Console.WriteLine("Calling j " + j); } }
38. == vs Equals()
== compares if the objects are same.
Equals match the content only even the object references are different.
static void Main(string[] args) { object string1 = "Test"; object string2 = string1; Console.WriteLine(string1==string2); Console.WriteLine(string1.Equals(string2)); }
Output – True
True
static void Main(string[] args) { object string1 = "Test"; object string2 = new string("Test".ToCharArray()); Console.WriteLine(string1==string2); Console.WriteLine(string1.Equals(string2)); }
Output – False
True
Conclusion
Hope you like the article on ASP.Net interview questions and answers.
Read Other Interview Questions and Answers –
MVC Interview Questions and Answers
Top Web API interview questions and answers
OOPS Interview Questions and Answers
C# Important interview questions and answers