.Net Questions

C# Interview Questions
A list of top frequently asked C# interview questions and answers are given below.
________________________________________
1) What is C#?
C# is a simple, modern, general purpose programming language. It is an object oriented programming language developed by Microsoft. It is a safe and managed language that is compiled by .NET framework to generate Microsoft intermediate language (machine code).
________________________________________
2) What is the reason behind the invention of C#?
C# is designed for Common Language Infrastructure (CLI). It contains the executable code and runtime environment that makes the users able to use various high-level languages on different computer platforms and architectures.
________________________________________
3) What are the main reasons to use C# language?
These are top reasons to use C# language:
o Easy to learn
o General purpose and object oriented programming language
o Component oriented
o Structured language
o Can be compiled on variety of computer platforms
o Produces efficient programs
o Part of .net framework

________________________________________
4) What is the difference between public, static and void?
You can access public declared variables anywhere in the application.
Static declared variables are globally accessible without creating an instance of the class.
Void is a type modifier that specifies that the method doesn’t return any value.

5) What are constructors in C#?
A constructor is a member function in the class and has the same name as its class. Whenever the object class is created, the constructor is automatically invoked. It constructs the value of data members while initializing the class.
________________________________________
6) What are the different types of constructors in C#?
Basically, there are five types of constructors:
o Static constructor
o Private constructor
o Copy constructor
o Default constructor
o Parameterized constructor
________________________________________
7) What is static constructor?
Static constructor is used to initialize static data members as soon as the class is referenced first time.
________________________________________
8) What is method overloading in C#?
Method overloading is mechanism to create multiple methods with the same name and unique signature in the same class. When you go for compilation, the compiler uses overload resolution to determine the specific method to be invoked.
________________________________________
9) Is overriding of a function possible in the same class?
No
________________________________________
10) What is array?
Array is a set of related instances either value or reference types.
There are three types of array supported by C#:
o Single Dimensional Array: It contains a single row. It is also known as vector array.
o Multi Dimensional Array: It is rectangular and contains rows and columns.
o Jagged Array: It also contains rows and columns but it has an irregular shape.
________________________________________
11) What is ArrayList?
ArrayList is a dynamic array. You can add and remove the elements from an ArrayList at runtime. In the ArrayList, elements are not automatically sorted.
________________________________________
12) What is a collection?
A collection works as a container for instances of other classes. All classes implement ICollection interface.
________________________________________
13) What is an interface?
Interface is an abstract class that has only public abstract method. These methods only have declaration not the definition. These abstract methods must be implemented in the inherited classes.
________________________________________
14) What is the lock statement in C#?
Lock statement is used to ensure that one thread doesn?t enter a critical section of code while another thread is in the critical section. If another thread attempts to enter a locked code it will wait, block, until the object is released.
________________________________________
15) What is serialization?
If you want to transport an object through network then you have to convert the object into a stream of bytes. The process of converting an object into a stream of bytes is called serialization.
________________________________________
16) How to declare a property in a class?
1. int m_PersonID = 0;
2. public int PersonID
3. {
4. get { return m_PersonID; }
5. set { m_PersonID = value; }
6. }
________________________________________

17) What is the difference between early binding and late binding in C#?
Early binding and late binding are the concept of polymorphism. There are two types of polymorphism in C#.
o Compile Time Polymorphism: It is also known as early binding.
o Run Time Polymorphism: It is also known as late binding or method overriding or dynamic polymorphism.
________________________________________
18) Which are the access modifiers available in C#?
Following are the access modifiers generally used for accessibility:
o Public: If you define an attribute or method as public, it can be accessed from any code of the project.
o Private: A private defined attribute or method can be accessed by any code within the containing class only.
o Protected: If you define the method or attribute as protected it can be accessed by any method in the inherited classes and any method within the same class.
o Internal: If you define an attribute or a method as internal, it is restricted to classes within the current position assembly.
o Protected internal: If you define an attribute or method as protected internal, access is restricted to classes within the current project assembly or types derived from the containing class.
________________________________________
19) What is the difference between abstract class and interface in C#?
Abstract class can have abstract and concrete methods whereas interface has only abstract methods.
________________________________________
20) What is the difference between dispose() and finalize() methods in C#?
The dispose() method is explicitly called by user to free unmanaged resources such as files, database connections etc whereas finalize() method is implicitly called by garbage collector to free unmanaged resources like files, database connections etc.
The dispose() method belongs to IDisposable interface whereas finalize() method belongs the Object class.
________________________________________

21) What is the difference between method overloading and method overriding in C#?
Method parameters must be different in method overloading whereas it must be same in method overriding.
Inheritance is not required in method overloading, it occurs within the same class. But inheritance is required in method overriding.
________________________________________
22) What is object pool in .Net?
Object pool is a container of ready to use objects. It reduces the overhead of creating new object.
________________________________________
23) What is delegate in C#?
A delegate in C# is an object that holds the reference to a method. It is like function pointer in C++.
________________________________________
24) What is Hashtable?
A Hashtable is a collection of key/value pairs. It contains values based on the key.
________________________________________
25) What is Reflection?
Reflection allows us to get metadata and assemblies of an object at runtime.
________________________________________
26) What is Garbage Collection?
Garbage Collection is a process of releasing memory automatically occupied by objects which are no longer accessible.
27) What is ASP?
ASP stands for Active Server Pages. It is also known as classic ASP. It is a server side technology provided by Microsoft which is used to create dynamic and user-friendly web pages. It uses different scripting languages to create dynamic web pages which can be run on any type of browsers.
________________________________________
28) What is ASP.NET?
ASP.Net is a specification by Microsoft which is used to create web applications and web services. It is a part of .Net framework. You can create ASP.Net applications in most of the .Net compatible languages like Visual Basic, C# etc. ASP.Net provides much better performance than scripting languages.
________________________________________
29) What is the difference between the ASP and ASP.NET?
The main difference between ASP and ASP.Net is that ASP is interpreted, while ASP.Net is compiled. ASP uses VBScript, therefore when the ASP page is executed, it is interpreted. On the other hand, ASP.Net uses .Net languages like C# and VB.NET, which is compiled to Microsoft intermediate language.
________________________________________
29) What are the advantages of ASP.NET?
ASP.Net is the next generation of ASP technology platform. It is superior to ASP in the following ways:
o Highly Scalable
o Compiled Code
o User Authentication
o Language Support
o Third party control
o Configuration and Deployment is easy.
o Object and Page caching
o Strict coding requirements
________________________________________
30) What is the concept of Postback in ASP.NET?
Postback is a request which is sent from a client to the server from the same page user is working with. There is HTTP POST request mechanism in ASP.NET. It basically posts a complete page back to server to refresh the whole page.
________________________________________
31) How to check that the page is Post Back?
The “isPostBack” property of page object is used to check that the page is posted back or not.
________________________________________
32) What is the parent class of all web server control?
System.Web.UI.Control class
________________________________________
33) What is the difference between ASP.NET Webforms and ASP.NET MVC?
ASP.NET Webforms uses the page controller approach for rendering layout. In this approach, every page has its own controller.
On the other hand, ASP.NET MVC uses Front Controller approach. In this approach, there is a common controller for all pages.
________________________________________
34) What is the difference between GET method () and POST method ()?
No. get method( ) post method( )
1. Data is affixed to the url. Data is not affixed to the url.
2. Data is not secured. Data is secured.
3. Data transmission is faster in this method. Data transmission is comparatively slow.
4. This is a single call system. This is a two call system.
5. Only limited amount of data can be sent. Large amount of data can be sent.
6. It is a default method for many browsers. It is not set as default. it should be explicitly specified.

35) What is the difference between session object and application object??
The session object is used to maintain the session of each user. A session id is generated if a user enters in the application and when the user leaves the application, the session id is automatically deleted.
On the other hand, application object is used to store the information and access variables from any page in the application.
________________________________________
36) How to sign out from forms authentication?
FormsAuthentication.Signout() method is used to sign out from forms authentication.
________________________________________
37) How to display validation messages in one control?
By the help of ValidationSummary control, we can display all validation messages in one control.
________________________________________
38) What is the difference between authentication and authorization?
Authentication is a process of identifying user whereas authorization is used to check the access rights of an identified user.
________________________________________
39) Which object encapsulates state or data of an user?
Session object.
________________________________________
40) What is ViewState?
ViewState is a features of ASP.NET to store the values of a page before it is submitted to the server. After posting the page, data from is ViewState is restored.
________________________________________
41) What is ViewState information stored?
It is stored in HTML hidden field.
________________________________________
42) What are the differences between the Response.Write() and Response.Output.Write()?
Response.Write() is used for normal output whereas Response.Output.Write() is used for formatted output.
________________________________________
43) Define the types of configuration files.
There are two types of configuration files:
o Application Level config = Web.config.
o Machine Level config = Machine.config.
________________________________________
44) What is the difference between Web config and Machine config files?
Web config file is specific to web application whereas Machine config file is specific to machine or server.
There can be multiple web config files in an application but only one machine config file.
________________________________________
45) What is MVC?
MVC stands for Model View Controller. It is a design pattern that is used to separate business logic and presentation logic. It is used to develop highly customized application.
Model represents data, View represents presentation and controller acts as an interface between Model and View.
________________________________________
46) What are the built-in objects in ASP.NET?
The major built-in objects are given below:
o Application
o Session
o Context
o Request
o Response
o Server
o Trace
________________________________________
47) What is Role-base security?
In role-based security, you can assign a role to each user. In such way, each user has privilege to do some task.
________________________________________
48) What is cookie?
Cookie is a small piece of information which is stored at client side. There are two types of cookie:
o Session/Temporary Cookie: valid for single session
o Persistent Cookie: valid for multiple session
________________________________________
49) What is the default timeout for cookie?
30 minutes.
________________________________________
50) Which protocol is used to call web service?
HTTP protocol.
________________________________________
51) What is the file extension of web service?
File extension of web service is .asmx.
52) What is ADO.NET?
ADO.NET stands for ActiveX Data Objects. It is a major component of .NET framework. It is designed to connect with different databases like SQL, MySQL, Oracle, and MS Access etc.
________________________________________
53) What are the objects of ADO.NET?
The two important objects of ADO.Net are:
o DataReader
o DataSet
________________________________________
54) What does DataReader Object?
The DataReader object of ADO.NET is used to provide access of data from a specified data source. It contains classes to sequentially read data from a data source like Oracle, MS Access, SQL Server etc.
________________________________________
55) Can we load multiple tables in a Dataset?
Yes, you can load multiple tables in a dataset.
________________________________________
56) What are the important features of ADO.NET?
o ADO.NET provides in built classes to make connection with databases like Oracle, SQL Server, MySQL, MS Access etc.
o ADO.NET provides in built classes for data manipulation operations like Insert, Update, Delete and Select data.
o Provide a functionality to combine data from different data sources.
o Disconnect data architecture for better performance.
________________________________________
57) What are the advantages of ADO.NET?
Following are the advantages of ADO.NET:
o Programmability
o Maintainability
o Interoperability
o Performance
o Scalability
________________________________________
58) What are the main differences between classic ADO and ADO.NET?
These are the main differences between ADO and ADO.NET:
ADO ADO.NET
ADO have record set. ADO.NET have data adopter and data set.
The objects of ado communicate in binary mode. It uses xml for passing the data.
It supports mostly connection oriented models. It works in disconnected manners.
It derives information about data implicitly at run time based on metadata so it is a costly process. It uses known metadata at design time so it provides better run time performance and more consistent run time behavior.
It allows only client side cursors. It supports both client side and server side cursors.
59) What is LINQ?
LINQ is a native query language for .NET framework. It is specially designed to support queries with .NET applications. It can be connected with SQL and MS Access.
________________________________________
60) Is it possible to edit data in Repeater control?
No. It is read-only and forward-only control so it is not possible to edit data in repeater control.
________________________________________
61) Which ADO.NET object is very fast in getting data from database?
SqlDataReader object.
________________________________________
62) What is connection pooling?
Connection pooling contains database collections so that the connection can be used or reused whenever there is a request to the database. This technique increases the performance of executing the database commands because there is no need to create new connection.
________________________________________
63) What are the ADO.NET connection pooling parameters?
o Connection Lifetime: default values is 0.
o Connection Timeout: default values is 15.
o Max Pool Size: default values is 100.
o Min Pool Size: default values is 0.
o Pooling: default values is true.
o Incr Pool Size: default values is 5.
o Decr Pool Size: default values is 1.
________________________________________
64) Do you use stored procedure in ADO.NET?
Yes, You can use stored procedure in ADO.NET. It makes the performance fast because stored procedures are precompiled.
________________________________________
65) What is the use of Dataview?
Dataview is used to represent a whole table or a part of table. It is used for sorting and searching data in the data table.
________________________________________
66) What are the data providers used in ADO.NET
Following are the data providers used in ADO.NET:
o MS SQL Server
o OLEDB
o ODBC
________________________________________
67) What is the difference between Data Reader and Data Adapter?
Data Reader Data Adopter
Data reader is read only, forward only. it is much faster than data adopter. It is comparatively slower.
Data reader facilitates you to open and close connection explicitly. If you use data adopter, the connection is automatically open and closed.
Data reader makes connection to database to perform any operation on data. Data adopter is disconnected
68) What are the different layers of ADO.NET?
Following are three different layers of ADO.NET:
o Presentation Layer
o Business Logic Layer
o Database Access Layer
________________________________________
69) Why is stored procedure used in ADO.NET?
Stored Procedure is used for following reasons:
o To improve performance
o Easy to use and maintain
o For security
o Less time taking for execution
o Less Network Traffic
________________________________________

70) What are the several execute methods of ADO.NET?
These are the different execute methods of ADO.NET command object:
o ExecuteScalar: It returns single value from the dataset.
o ExecutenonQuery: It has multiple values and returns resultset from dataset.
o ExecuteReader: Forwardonly Resultset.
o ExecuteXMLReader: Build XMLReader object from the SQL Query.

Advertisements