You are on page 1of 13

DOTNET INTERVIEW QUESTION WITH ANSWERS

1. What are a base class and derived class?

Ans: The base class is a class whose members and functions can be inherited, and the
derived class is the class that inherits those members and may also have additional
properties.  

2. What is the extension method for a class?

Ans: The extension method is used to add new methods in the existing class or the
structure without modifying the source code of the original type. Special permission
from the original type or re-compiling it isn’t required.

3. What is inheritance?

Ans: Inheritance is a method for creating hierarchies of objects wherein one class,


called a subclass, is based on another class, called a base class.\

4. What are implementation inheritance and interface inheritance?

Ans: Implementation inheritance is when a class inherits all members of the class from
which it is derived. Interface inheritance is when the class inherits only signatures of
the functions from another class.

5. What is a constructor in C#?

Ans: A constructor is a special method of the class that contains a collection of


instructions and gets automatically invoked when an instance of the class is created.

6. Explain Different Types of Constructors in C#?

Ans: There are 5 types of constructors in C#, as given below:

 Default Constructor: It is without any parameters.


 Parameterized Constructor: It has one parameter.
 Copy Constructor: It creates an object by copying variables from another
object.
 Static Constructor: It is created using a static keyword and will be invoked only
once for all of the instances of the class.
 Private Constructor: It is created with a private specifier and does not allow
other classes to derive from this class or create an instance of it.
DOTNET INTERVIEW QUESTION WITH ANSWERS

7. Define Method Overriding?

Ans: Method Overriding is a process that allows using the same name, return type,
argument, and invoking the same functions from another class (base class) in the
derived class.

8. Do we have multiple inheritances in .NET? Why?

Ans: No, .NET supports only single inheritance due to the diamond problem. Also, it
would add complexity when used in different languages. However, multiple interfaces
can solve the purpose.

9. What is an Interface?

Ans: An interface is a declaration for a set of class members. It is a reference type that
contains only abstract members such as Events, Methods, Properties, etc.

10. What are the events and delegates?

Ans: Events notify other classes and objects when the desired action occurs in a class
or object. A delegate is a type-safe function pointer that defines a method signature in
CLI.

11. What are globalization and localization?

Ans: Globalization is designing and coding culture-neutral and language-neutral


applications. Localization is customizing the application and translating the UI based on
specific cultures and regions.

12. What is the difference between trace class and debug class?

Ans: The call to Debug class is included in Debug mode only and it is used at the time
of application development. While the call to Trace class will be included in Debug as
well as Release mode also and it is used at the time of application deployment.

13. What is MVC?

Ans: MVC is an architectural model for building .Net applications. It stands for Model
View Controller. It is easy to use and offers full control over the HTML.

14. Explain the difference between Function and Stored procedure?


DOTNET INTERVIEW QUESTION WITH ANSWERS

Ans: Stored Procedures are pre-compiled objects which execute the code when called
for. While a Function is compiled and executed when it is called for.

15. What is ADO?

Ans: ADO stands for ActiveX Data Objects. It is an application program for writing
Windows applications. It is used to get access to a relational or non-relational database
from database providers such as Microsoft and others.

16. What are the fundamental objects in ADO.NET?

Ans: There are two fundamental objects in ADO.NET:

i. DataReader: connected architecture.

ii. DataSet: disconnected architecture.

17. What is Serialization?

Ans: Serialization is the process of converting the state of an object into a form (a


stream of bytes) to be persisted or transported. Deserialization converts a stream into
an object and is the opposite of serialization. These processes allow data to be stored
and transferred.

18. Differentiate between Task and Thread in .NET?

Ans: The thread represents an actual OS-level thread, with its own stack and kernel
resources, and allows the highest degree of control. You can choose to Abort() or
Suspend() or Resume() a thread, and set thread-level properties, like the stack size,
apartment state, or culture. While a Task class from the Task Parallel Library is
executed by a TaskScheduler to return a result and allows you to find out when it
finishes.

19. What is Multithreading?

Ans: Multi-threading is a process that contains multiple threads each of which


performs different activities within a single process. .NET supports multithreading in
two ways:

1. Starting threads with ThreadStart delegates.


2. Using the ThreadPool class with asynchronous methods.
DOTNET INTERVIEW QUESTION WITH ANSWERS

20. What are the basic features of OOP?

Ans: The basic features of OOP are:

 Encapsulation: Creation of self-contained modules that bind together the data


and the functions that access that data.
 Abstraction: Handles complexity and allows the implementation of further
complex logic without disclosing it to the user object.
 Polymorphism: Operation performed depends upon the context at runtime to
facilitate easy integration.
 Inheritance:  Creation of classes in a hierarchy to enable a class to inherit
behavior from its parent class allowing reuse of code.

21. What is JIT?

Ans: JIT stands for Just In Time. It is a compiler in CLR responsible for the execution
of .NET programs of different languages by converting them into machine code. It
speeds up the code execution and supports multiple platforms.

22. What are the different types of JIT Compilers?

Ans: There are 3 types of JIT Compilers:

i. Pre-JIT compiler: It compiles all the source code into the machine code in a single
compilation cycle, i.e. at the application deployment time.

ii. Normal JIT Compiler: The source code methods required at run-time are compiled
into machine code and stored in the cache to be called later.

iii. Econo JIT Compiler:  The methods required only at run-time are compiled using
this compiler and they are not stored for future use.

23. What is the difference between a function and a


stored procedure in .NET?
Function Stored Procedure
Can only return one value Can return any number of values
DOTNET INTERVIEW QUESTION WITH ANSWERS

No support for exception handling using Supports the usage of try-catch blocks for
try-catch blocks exception handling
The argument consists of only one input Both input and output parameters are
parameter present
A function can be called from a stored The stored procedure cannot be called
procedure from a function

23. What is the difference between an abstract class and


an interface in .NET?
Abstract Class Interface
Provides the partial implementation of Used to declare the behavior of an
functionalities that are done by inheriting implementing class
classes
Used to declare properties, methods, Feilds cannot be declared using
events, and fields as well interfaces

C# part2
1. How is Exception Handling implemented in C#?
You can carry out exception handling using the following four keywords in C#:

 try: It has a code block for which an exception is checked.


 catch: This program catches an exception with the assistance of an
exception handler.
 finally: It is a code block written to execute irrespective of the exception
being caught or not.
 throw: It throws an exception whenever a problem takes place.

 Q2. How is overloading different from


overriding?
DOTNET INTERVIEW QUESTION WITH ANSWERS

 The following table enumerates the key differences between overloading and
overriding. 

Q3. What do you understand about dependency


injection?
You can de-couple tightly linked classes using the dependency injection. Thus, it
reduces the direct dependency of classes upon each other. You can achieve
dependency injection via the following: 

 Constructor dependency
 Property dependency
 Method dependency

4. What types of joins do you know?

 (INNER) JOIN – returns only those records that satisfy a defined join
condition in both (or all) tables. It's a default SQL join.
 LEFT (OUTER) JOIN – returns all records from the left table and those
records from the right table that satisfy a defined join condition.
 RIGHT (OUTER) JOIN – returns all records from the right table and those
records from the left table that satisfy a defined join condition.
 FULL (OUTER) JOIN –
returns all records from both (or all) tables. It can be
considered as a combination of left and right joins
DOTNET INTERVIEW QUESTION WITH ANSWERS

5. What is a primary key?


A column (or multiple columns) of a table to which the PRIMARY KEY constraint was imposed to
ensure unique and non-null values in that column. In other words, a primary key is a combination
of the NOT NULL and UNIQUE constraints. The primary key uniquely identifies each record of the
table. Each table should contain a primary key and can't contain more than one primary key.

6. What is a unique key?


A column (or multiple columns) of a table to which the UNIQUE constraint was imposed to
ensure unique values in that column, including a possible NULL value (the only one).

7. What is a foreign key?


A column (or multiple columns) of a table to which the FOREIGN KEY constraint was imposed to
link this column to the primary key in another table (or several tables). The purpose of foreign
keys is to keep connected various tables of a database.

8. What is the difference between value type and reference type


Reference Types: 
 Always allocated from the managed heap.
 Always represented in boxed form.
 When we assign a value type to another value type, a field-by-field copy is
made.
Value Types: 
 Allocated on thread's stack
 Have two form representations "boxed" and "unboxed"
 When we copy a reference type to another reference type, only the memory
address is copied.

9. What is the difference between IEnumerable and ICollection?

IEnumerable interface has only single method - GetEnumerator() and it must return
an instance of an object of a class which implements the IEnumerator interface.

ICollection inherits IEnumerable apart from it contains some more method and
IsSynchronized and SyncRoot properties help to make the collection thread-safe.
ICollection supports count property too.
DOTNET INTERVIEW QUESTION WITH ANSWERS

10.What is Sealed Class in C#

A class from which it is not possible to create/derive a new class is known as a sealed
class. In simple words, we can say that when we define the class using the sealed modifier,
then it is known as a sealed class and a sealed class cannot be inherited by any other
classes.

What is middleware?
It is software that is injected into the application pipeline to handle requests and
responses. They are just like chained to each other and form as a pipeline. The incoming
requests are passed through this pipeline where all middleware is configured, and
middleware can perform some action on the request before passing it to the next
middleware. Same as for the responses, they are also passing through the middleware
but in reverse order.
DOTNET INTERVIEW QUESTION WITH ANSWERS

What is the startup class in ASP.NET core?


The startup class is the entry point of the ASP.NET Core application. Every .NET Core
application must have this class. This class contains the application configuration related
items. It is not necessary that the class name must be "Startup", it can be anything, we
can configure the startup class in the Program class

8. What is the life cycle of an MVC Application?

The lifecycle of an MVC application includes two execution steps and two
main phases. The two execution steps involve understanding the request and,
secondly, sending out the most appropriate response based on the type of
request. The two main phases include creating the request object and,
secondly, sending the response to the browser.

0. What are the differences between View data and View Bag?

 View data can pass the data from a controller to view, while View bag
can pass data from the controller to the respective view.
 View data is available for current requests only, while View bag is
available for all kinds of requests.
 View data needs typecasting for complex data, while View bag does not
require any kind of typecasting.

35. What are the different types of validators?

Types of validators include Range, Required, DataType, and StringLength.

. What is the difference between RenderBody and RenderPage?

The RenderBody supports web forms as a ContentPlaceHolder. It renders child


pages or child views on the existing page layout. The Render page is part of
DOTNET INTERVIEW QUESTION WITH ANSWERS

the layout page. At one time, there can be multiple instances of RenderPage in
the RenderBody. 

What is the difference between SQL and MySQL?

SQL is a standard language for retrieving and manipulating structured databases. On


the contrary, MySQL is a relational database management system, like SQL Server,
Oracle or IBM DB2, that is used to manage SQL databases.

7. What are Constraints in SQL?

Constraints are used to specify the rules concerning data in the table. It can be applied
for single or multiple fields in an SQL table during the creation of the table or after
creating using the ALTER TABLE command. The constraints are:

 NOT NULL - Restricts NULL value from being inserted into a column.
 CHECK - Verifies that all values in a field satisfy a condition.
 DEFAULT - Automatically assigns a default value if no value has been specified
for the field.
 UNIQUE - Ensures unique values to be inserted into the field.
 INDEX - Indexes a field providing faster retrieval of records.
 PRIMARY KEY - Uniquely identifies each record in a table.
 FOREIGN KEY - Ensures referential integrity for a record in another tabl

22. What is Cursor? How to use a Cursor?

A database cursor is a control structure that allows for the traversal of records in a
database. Cursors, in addition, facilitates processing after traversal, such as retrieval,
addition, and deletion of database records. They can be viewed as a pointer to one row
in a set of rows.

. 14.What is a Stored Procedure?

A stored procedure is a subroutine available to applications that access a relational


database management system (RDBMS). Such procedures are stored in the database
data dictionary. The sole disadvantage of stored procedure is that it can be executed
nowhere except in the database and occupies more memory in the database server. It
also provides a sense of security and functionality as users who can't access the data
directly can be granted access via stored procedures.

13.Why is class an abstract data type?


DOTNET INTERVIEW QUESTION WITH ANSWERS
A Class is an Abstract Data Type because it specifies what data members and member
functions (methods) contain in it (class), but it does not provide information on how those
are implemented. That makes Class Abstract and Class is User Defined DataType. So, it’s
an Abstract Data Type

12.What is the difference between an implicit conversion and an explicit


conversion? 
Explicit conversions require a cast operator whereas an implicit conversion is done
automatically. The Explicit conversion can lead to data loss whereas with implicit
conversions there is no data loss

11.Types of Delegates in C#:


Delegates are classified into two types such as
1. Single cast delegate
2. Multicast delegate
If a delegate is used for invoking a single method then it is called a single cast delegate or
unicast delegate. OR the delegates that represent only a single function is known as a
single cast delegate.
If a delegate is used for invoking multiple methods then it is known as the multicast
delegate. OR the delegates that represent more than one function are called Multicast
delegate.

01.What is Scaffolding?
Scaffolding is basically a Code Generation framework. Scaffolding Engine generates basic
controllers as well as views for the models using Microsoft’s T4 template. Scaffolding blends
with Entity Framework and creates the instance for the mapped entity model and generates
code of all CRUD Operations. Further, we can edit or customize this auto-generated code
according to our needs. As a result, we get the basic structure for a tedious and repetitive
task.

02.What are HTML Helpers in ASP.NET MVC?


ASP.NET Web Forms can map the HTML helper methods to Web Form Controls because
both serve the same purpose. But HTML helpers are comparatively lightweight because
they don’t have view state and event like Web Form Controls. Along with the built-in HTML
helpers, it is also possible to create our own custom helper methods to fulfill our specific
purpose. For example, we can create custom HTML Helpers to render more complex
content such as a menu strip or an HTML table for displaying database data.

03.What is Caching?
Caching is the most important aspect of a high-performance web application. Caching
provides a way of storing frequently accessed data and reusing that data. Practically, this is
an effective way of improving the web application’s performance

04.How to Request Web API Service to Return Data in JSON Format?


The JSON format is currently the most popular format of data representation. So, first, we
will see how to return the data in JSON format from the ASP.NET Web API Application. We
DOTNET INTERVIEW QUESTION WITH ANSWERS
are going to use a tool called Fiddler to test the Web API services. So please read how to
use Fiddler to test the web API tutorial before proceeding to this article. Even you can
also use Postman to test the services.

Authentication is the process of identifying the user. For example, one user let’s say
James logs in with his username and password, and the server uses his username and
password to authenticate James.
Authorization is the process of deciding whether the authenticated user is allowed to
perform an action on a specific resource (Web API Resource) or not. For example, James
(who is an authenticated user) has the permission to get a resource but does not have the
permission to create a resource.

05.Why Singleton Class is Sealed in C#?


, create the Singleton class without using the sealed keyword. Then create another class
with the name DerivedSingleton and Inherit the DerivedSingleton from the singleton class a

06.What is Non-Lazy or Eager Loading in C#?


The Eager Loading or Non-Lazy Loading in C# is nothing but a process in which we need to
initialize the Singleton Object at the time of application start-up rather than on-demand and
keep it ready in memory to be used in the future. The advantage of using Eager Loading in
the Singleton Design Pattern is that the CLR (Common Language Runtime) will take care of
Object Initialization and Thread Safety in Multithread Environment. That means we will not
require to write any code explicitly for handling the thread safety for a multithreaded
environment.

07.What is Lazy Loading or Deferred Loading in C#?


Lazy Loading or Deferred Loading in C# is nothing but a concept that is commonly used to
delay the initialization of an object until the point at which it is needed. So the main objective
of Lazy Loading or Deferred Loading is to load the object on-demand or you can say object
when needed. The most important point that you need to keep in mind is that you need to
use Lazy loading when the cost of the object creation is very high as well as the use of that
object is very rare. Lazy loading improves the performance of an application if it is used
properly. 

08.What is Method Dependency Injection in C#?


In Method Dependency Injection, we need to supply the dependency object through a public
method of the client class. Let us see an example to understand how we can implement the
Method Dependency Injection in C#. Let us modify the EmployeeBL class as shown below.
Here, you can see, the GetAllEmployees method, takes one parameter of the dependency
object, and using that parameter, it is invoking the service method.

09.What is a Stored Procedure in SQL Server?


A SQL Server Stored Procedure is a database object which contains pre-compiled queries
(a group of T-SQL Statements). In other words, we can say that the Stored Procedures are
a block of code designed to perform a task whenever we called.
DOTNET INTERVIEW QUESTION WITH ANSWERS

10.How can we create a Stored Procedure in SQL Server?


In SQL Server, you can create a stored procedure by using the CREATE
PROCEDURE or CREATE PROC statement. Again, you can create a procedure with or
without parameters. Please have a look at the below image f

11.Types of Constructors in C#
There are five types of constructors available in C#, they are as follows
1. Default or Parameter Less Constructor
2. Parameterized Constructor
3. Copy Constructor
4. Static Constructor
5. Private Constructor

You might also like