REAL TIME Dot Net Interview Question & Answer For [PRACTICE]
Last updated on 05th Jun 2020, Blog, Interview Questions
.NET is referred to as a software development platform that is used in various languages. It offers interoperability of languages which enables each language to be used in other languages. The dot net structure consists of a class library called FCL. It follows the principle of interoperability, language-independent, type of security, portability, security, memory management, and performance.
1. What is .NET?
.NET is a framework for software development. It is just like other software development frameworks like (J2EE). It provides runtime capabilities and a rich set of pre-built functionality in the form of class libraries and APIs. This .NET framework is an environment to build, deploy and run web services and other applications.
The .NET framework contains three main parts:
- Common Language Runtime
- Framework classes
2. How many languages are supported by .NET at present time?
When .NET was introduced first time, it supports many languages like VB.NET,C#,COBOL, and Perl etc. At present time it supports almost 44 languages.
3. How is it possible for .NET to support many languages?
The .NET language code is compiled to Microsoft Intermediate Language (MSIL). The generated code is called managed code. This managed code is run in .NET environment. So after compilation the language is not a barrier and the code can call or use functions of another language also.
4. Is ASP.NET different from ASP? If yes, explain how?
Yes, ASP.NET is different from ASP. These are the main differences:
- ASP.NET is developed by Microsoft to create dynamic web applications while ASP (Active Server Pages) is Microsoft’s server side technology used to create web pages.
- ASP.NET is compiled while ASP is interpreted.
- ASP uses the technology named ADO while ASP.NET uses ADO.NET.
- ASP.NET is completely object oriented while ASP is partially object oriented.
5. What is the state management in ASP.NET?
State management is a technique that is used to manage a state of an object on different requests. It is very important to manage state in any web application. There are two types of state management systems in ASP.NET.
- Client side state management
- Server side state management
6. What is the difference between trace and debug?
Debug class is used to debug builds while Trace is used for both debug and release builds.
7. What are the differences between system.stringbuilder and system.string?
The main differences between system.stringbuilder and system.string are:
- system.stringbuilder is a mutable while system.string is immutable.
- Append keyword is used in system.stringbuilder but not in system.string.
8. What is the difference between int and int32?
There is no difference between int and int32. System. Int is an alias name for System.Int32 which is a .Net Class.
9. What is the difference between namespace and assembly?
An assembly is a physical grouping of logical units while namespace groups classes. A namespace can span multiple assemblies.
10. Explain the differences between value type and reference type.
Following are the main differences between value type and reference type:
- Value type contains variables while reference type doesn’t contain value directly in its memory.
- In reference type, memory is allocated in managed heap and in value type memory allocated in stack.
- Reference type ex-class value type-struct, enumeration
11. What is the difference between session object and application object?
The session object is used to maintain the session of each user.
For example: If a user enters into the application then he will get a session id. If he leaves from the application then the session id is deleted. If he again enters into the application, he will get a different session id.
But in the case of an application object the id is maintained for the whole application.
12. What are differences between function and stored procedure in .Net programming language?
The difference between function and stored procedure:
- Function returns only one value but procedure can return one or more than one value.
- Function can be used in select statements but procedure cannot be used.
- Function has only input parameters while Procedure can have an input and output parameters.
- Exceptions can be handled by try-catch blocks in procedures but that is not possible in function.
13. How to retrieve user name in case of Window Authentication?
14. What is the difference between a Hash table and Array list?
- Hash table stores data in the form of value pair and name while Array list stores only values.
- You need to pass a name to access value from the Hash table while in Array, you need to pass index number to access value.
- In Array, you can store only similar data types while in a Hash table you can store different types of data types. ex. int, string etc.
15. What is the meaning of Immutable?
Immutable means once you create a thing, you cannot modify it.
For example: If you want to give new value to old value then it will discard the old value and create a new instance in memory to hold the new value.
16. What are the advantages of using a session?
The advantages of using session are:
- A session stores user states and data to all over the application.
- It is very easy to implement and we can store any kind of object.
- It can store every user data separately.
- Session is secure and transparent from the user because the session object is stored on the server.
17. What are the disadvantages of using a session?
The disadvantages of using session are:
- Performance overhead occurs in case of a large number of users, because session data is stored in server memory.
- Overhead involved in serializing and De-Serializing session Data. Because In case of StateServer and SQLServer session mode we need to serialize the object before store.
18. Can you set the session out time manually?
Yes. Session out time can be set manually in web.config.
19. Explain the boxing and unboxing concept in .Net?
- Boxing: Boxing is a process of converting value type into reference type.
- Unboxing: Unboxing is a process of converting reference type to value type.
20. Is it possible to change the index of the primary key on the table?
21. What is HTTPhandler?
HttpHandler is a low level request and response API which is made to service incoming Http requests. Every incoming Http request received by ASP.NET is ultimately processed by an instance of a class that implements HttpHandler.
22. What are the main components of .NET Framework?
Main components of .Net Framework:
- Class library
- Common Language Runtime (CLR)
- Dynamic Language Runtime (DLR)
- Application Domains
- Runtime Hosts
- Cross-language interoperability
- Framework security
- Profiling etc.
23. What is manifest in .NET Framework?
Manifest is used to store assembly metadata. It contains all the metadata which are necessary for following things.
- Version of assembly
- Security identity
- Scope of the assembly
- To resolve references to resources and classes
24. What are the memory-mapped files?
Memory-mapped files are used to map the content of a file to the logical address of an application. It makes it possible to run multiple processes on the same machine to share data with each other. To obtain a memory mapped file object, you can use the method MemoryMappedFile.CreateFromFiles( ). It represents a persistent memory-mapped file from a file on disk.
25. Which method is used to enforce garbage collection in .NET?
- System.GC.Collect() method.
26. What is the difference between dispose() and finalize()?
Although Dispose and Finalize both methods are used by CLR to perform garbage collection of runtime objects of .NET applications but there is a difference between them.
The Finalize method is called automatically by the runtime while the Dispose method is called by the programmer.
27. Explain the Code Access Security (CAS) in .NET framework.
.NET security model is used to prevent unauthorized access of resources and operations and also restrict the codes to perform particular tasks. Code Access Security is a part of that .NET security.
28. What is Garbage collection?
Garbage collection is used to prevent memory leaks during execution of programs. There is a low-priority process name as the garbage collector manages the allocation and deallocation of memory for applications. It also checks for the unreferenced variables and objects. If there is any object which is no further used by application the Garbage collector frees up the memory from that object.
29. How can you identify that the page is posted back?
There is a property, named as “IsPostBack” property. You can check it to know that the page is post backed or not.
30. What is variable and constant in .NET programming language?
Variable: A variable is a data storage location in the computer memory that contains a value and has a meaningful name. Every variable is attached to a data type which determines what type of value can be stored in the variable.
Variables can be declared by using the following syntax:
- <data_type> <variable_name>;
Constant: Constant is also similar to the variable except that the value. Value once assigned to a constant can’t be changed. Constants must be initialized at the same time they are declared.
Constants can be declared by using the following syntax:
- const int interestRate =10;
31. If you want to replace multiple if-else statements in code, which statement will you use?
In Visual basic, we can use Select-Case statements to replace multiple If-Else statements. In C#, we should use Switch-Case statements to replace multiple If-Else statements.
32. What are the different types of indexes in .Net?
There are two types of indexes in .Net:
Clustered index and non-clustered index
Get On-Demand .NET Training to Build Your Skills & Advance Your Career
- Instructor-led Sessions
- Real-life Case Studies
33. How many types of memories are there in .Net?
There are two types of memories in .Net
- Stack memory
- Heap Memory
34. Which are the new features added in .NET framework 4.0?
A list of new features of .NET Framework 4.0:
- Improved Application Compatibility and Deployment Support
- Dynamic Language Runtime
- Managed Extensibility Framework
- Parallel Programming framework
- Improved Security Model
- Networking Improvements
- Improved Core ASP.NET Services
- Improvements in WPF 4
- Improved Entity Framework (EF)
- Integration between WCF and WF
35. What are cookies?
A cookie is a small amount of data created by a server on the client. When a web server creates a cookie, an additional HTTP header is sent to the browser when a page is served to the browser.
36. What are the disadvantages of cookies?
The main disadvantages of cookies are:
- Cookies can store only string values.
- Cookies are browser dependent.
- Cookies are not secure.
- Cookies can store only a small amount of data.
37. What is an IL?
IL stands for Intermediate Language. It is also known as MSIL (Microsoft Intermediate Language) or CIL (Common Intermediate Language).
All .NET source codes are first compiled to IL. Then, IL is converted to machine code at the point where the software is installed, or at run-time by a Just-In-Time (JIT) compiler.
38. Which method is used to enforce garbage collection in .NET?
System.GC.Collect() method is used to enforce garbage collection in .Net.
39. What are tuples in .Net?
A tuple is a fixed-size collection that can have elements of either same or different data types. The user must have to specify the size of a tuple at the time of declaration just like arrays.
40. How many elements a tuple can hold?
A tuple can hold up from 1 to 8 elements. In the case of more than 8 elements, then the 8th element can be defined as another tuple. Tuples can be specified as parameters or return type of a method.
41. Which architecture does a Dataset follow?
A Dataset follows the disconnected data architecture.
42. How do you check whether a DataReader is closed or opened?
There is a property named “IsClosed” property is used to check whether a DataReader is closed or opened. This property returns a true value if a Data Reader is closed, otherwise a false value is returned.
43. What are the basic requirements for connection pooling?
The following two requirements must be fulfilled for connection pooling:
- There must be multiple processes to share the same connection describing the same parameters and security settings.
- The connection string must be identical.
44. Which adapter should be used to get the data from an Access database?
OleDbDataAdapter is used to get the data from an Access database.
45. What are the parameters that control most of connection pooling behaviors?
The following parameters control the connection pooling behavior:
- Connect Timeout
- Max Pool Size
- Min Pool Size
46. What do you mean by AutoPostBack?
AutoPostBack is a property which is used to postback automatically when an event is raised. You have to set the AutoPostBack property of the control to True.
47. Which properties are used to bind a DataGridView control?
The DataSource property and the DataMember property are used to bind a DataGridView control.
48. What is ASP.Net?
49. What’s the use of Response.Output.Write()?
We can write formatted output using Response.Output.Write().
50. In which event of the page cycle is the ViewState available?
After the Init() and before the Page_Load().
Learn Practical Oriented Dot Net Training from Real Time ExpertsWeekday / Weekend BatchesSee Batch Details
51. What is the difference between Server.Transfer and Response.Redirect?
- In Server.Transfer : page processing transfers from one page to the other page without making a round-trip back to the client’s browser. This provides a faster response with a little less overhead on the server. The clients url history list or current url Server does not update in case of Server.Transfer.
- Response.Redirect : is used to redirect the user’s browser to another page or site. It performs a trip back to the client where the client’s browser is redirected to the new page. The user’s browser history list is updated to reflect the new address.
52. From which base class all Web Forms are inherited?
53. What are the different validators in ASP.NET?
- Required field Validator
- Range Validator
- Compare Validator
- Custom Validator
- Regular expression Validator
- Summary Validator
54. Which validator control you use if you need to make sure the values in two different controls match?
Compare Validator control.
55. What is ViewState?
ViewState is used to retain the state of server-side objects between page post backs.
56. Where the viewstate is stored after the page postback?
ViewState is stored in a hidden field on the page at the client side. ViewState is transported to the client and back to the server, and is not stored on the server or any other external source.
57. How long the items in ViewState exist?
They exist for the life of the current page.
58. What are the different Session state management options available in ASP.NET?
In-Process: Stores the session in memory on the web server.
Out-of-Process: Session state management stores data in an external server. The external server may be either a SQL Server or a State Server. All objects stored in session are required to be serializable for Out-of-Process state management.
59. How can you add an event handler?
Using the Attributes property of server side control.
60. What is caching?
Caching is a technique used to increase performance by keeping frequently accessed data or files in memory. The request for a cached file/data will be accessed from cache instead of actual location of that file.
61. What are the different types of caching?
ASP.NET has 3 kinds of caching :
- Output Caching,
- Fragment Caching,
- Data Caching.
62. Which type of caching will be used if we want to cache the portion of a page instead of the whole page?
Fragment Caching: It caches the portion of the page generated by the request. For that, we can create user controls with the below code:
- <%@ OutputCache Duration=”120″ VaryByParam=”CategoryID;SelectedID”%>
63. List the events in the page life cycle.
64. Can we have a web application running without a web.Config file?
65. Is it possible to create a web application with both webforms and mvc?
Yes. We have to include below mvc assembly references in the web forms application to create hybrid applications.
66. Can we add code files of different languages in the App_Code folder?
No. The code files must be in the same language to be kept in the App_code folder.
67. What is Protected Configuration?
It is a feature used to secure connection string information.
68. Write code to send email from an ASP.NET application?
- MailMessage mailMess = new MailMessage ();
- mailMess.From = “email@example.com
- mailMess.To = “firstname.lastname@example.org”;
- mailMess.Subject = “Test email”;
- mailMess.Body = “Hi This is a test mail.”;
- SmtpMail.SmtpServer = “localhost”;
- SmtpMail.Send (mailMess);
- MailMessage and SmtpMail are classes defined System.Web.Mail namespace.
69. How can we prevent browsers from caching an ASPX page?
We can SetNoStore on HttpCachePolicy object exposed by the Response object’s Cache property:
- Response.Cache.SetNoStore ();
- Response.Write (DateTime.Now.ToLongTimeString ());
70. What is a good practice to implement validations in an aspx page?
Client-side validation is the best way to validate data of a web page. It reduces the network traffic and saves server resources.
71. What are the event handlers that we can have in the Global.asax file?
Session Events: Session_Start,Session_End
72. Which protocol is used to call a Web service?
73. Can we have multiple web config files for an asp.net application?
74. What is the difference between web config and machine config?
Web config file is specific to a web application whereas machine config is specific to a machine or server. There can be multiple web config files into an application where as we can have only one machine config file on a server.
75. Explain role based security ?
Role Based Security used to implement security based on roles assigned to user groups in the organization.
Then we can allow or deny users based on their role in the organization. Windows defines several built-in groups, including Administrators, Users, and Guests.
- <AUTHORIZATION>< authorization >
- < allow roles=”Domain_Name\Administrators” / > < !– Allow Administrators in domain. — >
- < deny users=”*” / > < !– Deny anyone else. — >
- < /authorization >
76. What is Cross Page Posting?
When we click the submit button on a web page, the page posts the data to the same page. The technique in which we post the data to different pages is called Cross Page posting. This can be achieved by setting POSTBACKURL property of the button that causes the postback. Findcontrol method of PreviousPage can be used to get the posted values on the page to which the page has been posted.
77. How can we apply Themes to an asp.net application?
We can specify the theme in the web.config file. Below is the code example to apply theme:
- <pages theme=”Windows7″ />
78. What is RedirectPermanent in ASP.Net?
RedirectPermanent Performs a permanent redirection from the requested URL to the specified URL. Once the redirection is done, it also returns 301 Moved Permanently responses.
79. What is MVC?
MVC is a framework used to create web applications. The web application base builds on the Model-View-Controller pattern which separates the application logic from UI, and the input and events from the user will be controlled by the Controller.
80. Explain the working of passport authentication.
First of all it checks the passport authentication cookie. If the cookie is not available then the application redirects the user to Passport Sign on page. Passport service authenticates the user details on sign on page and if valid then stores the authenticated cookie on client machine and then redirect the user to requested page
81. What are the advantages of Passport authentication?
- All the websites can be accessed using single login credentials. So no need to remember login credentials for each web site.
- Users can maintain his/ her information in a single location.
82. What are the asp.net Security Controls?
- <asp:Login>: Provides a standard login capability that allows the users to enter their credentials
- <asp:LoginName>: Allows you to display the name of the logged-in user
- <asp:LoginStatus>: Displays whether the user is authenticated or not
- <asp:LoginView>: Provides various login views depending on the selected template
- <asp:PasswordRecovery>: email the users their lost password
84. In which event are the controls fully loaded?
- Page load event.
- Unboxing is reverse of boxing ie. Assigning reference type variable to value type variable.
86. Differentiate strong typing and weak typing
In strong typing, the data types of variables are checked at compile time. On the other hand, in case of weak typing the variable data types are checked at runtime. In case of strong typing, there is no chance of compilation error. Scripts use weak typing and hence issues arise at runtime.
87. How can we force all the validation controls to run?
The Page.Validate() method is used to force all the validation controls to run and to perform validation.
88. List all templates of the Repeater control.
89. List the major built-in objects in ASP.NET?
90. What is the appSettings Section in the web.config file?
The appSettings block in the web config file sets the user-defined values for the whole application.
For example, in the following code snippet, the specified ConnectionString section is used throughout the project for database connection:
- <add key=”ConnectionString” value=”server=local; pwd=password; database=default” />
91. Which data type does the RangeValidator control support?
The data types supported by the RangeValidator control are Integer, Double, String, Currency, and Date.
92. What is the difference between an HtmlInputCheckBox control and an HtmlInputRadioButton control?
In HtmlInputCheckBoxcontrol, multiple item selection is possible whereas in HtmlInputRadioButton controls, we can select only a single item from the group of items.
93. Which namespaces are necessary to create a localized application?
94. What are the different types of cookies in ASP.NET?
- Session Cookie :Resides on the client machine for a single session until the user does not log out.
- Persistent Cookie : Resides on a user’s machine for a period specified for its expiry, such as 10 days, one month, and never.
95. What is the file extension of web service?
Web services have file extension .asmx..
96. What are the components of ADO.NET?
The components of ADO.Net are Dataset, Data Reader, Data Adaptor, Command, connection.
97. What is the difference between ExecuteScalar and ExecuteNonQuery?
ExecuteScalar returns output value whereas ExecuteNonQuery does not return any value but the number of rows affected by the query. ExecuteScalar used for fetching a single value and ExecuteNonQuery used to execute Insert and Update statements.
99. What is CTS?
CTS stands for Common Type System. It has a set of rules which state how a data type should be declared, defined and used in the program. It describes the data types that are to be used in the application.
We can design our own classes and values by following the rules that are present in the CTS. The rules are made so that the data type declared using a programming language can be called by an application that is developed using a different language.
100. What is CLR?
CLR stands for Common Language Runtime. It is one of the most important components of the .Net framework. It provides building blocks for many applications.
An application built using C# gets compiled by its own compiler and is converted into an Intermediate language. This is then targeted to CLR. CLR does various operations like memory management, security checks, assemblies to be loaded and thread management. It provides a secure execution environment for applications.