1. What is a data type? How many types of data types are there in .NET ?
A data type is a data storage format that can contain a specific type or range of values. Whenever you declare variables, each variable must be assigned a specific data type. Some common data types include integers, floating point, characters, and strings. The following are the two types of data types available in .NET:
- Value type – Refers to the data type that contains the data. In other words, the exact value or the data is directly stored in this data type. It means that when you assign a value type variable to another variable, then it copies the value rather than copying the reference of that variable. When you create a value type variable, a single space in memory is allocated to store the value (stack memory). Primitive data types, such as int, float, and char are examples of value type variables.
- Reference type – Refers to a data type that can access data by reference. Reference is a value or an address that accesses a particular data by address, which is stored elsewhere in memory (heap memory). You can say that reference is the physical address of data, where the data is stored in memory or in the storage device. Some built-in reference types variables in .Net are string, array, and object.
2. Differentiate between the while and for loop in C#.
The while and for loops are used to execute those units of code that need to be repeatedly executed, unless the result of the specified condition evaluates to false. The only difference between the two is in their syntax. The for loop is distinguished by setting an explicit loop variable.
3. What is a parameter? Explain the new types of parameters introduced in C# 4.0.
A parameter is a special kind of variable, which is used in a function to provide a piece of information or input to a caller function. These inputs are called arguments. In C#, the different types of parameters are as follows:
- Value type – Refers that you do not need to provide any keyword with a parameter.
- Reference type – Refers that you need to mention the ref keyword with a parameter.
- Output type – Refers that you need to mention the out keyword with a parameter.
- Optional parameter – Refers to the new parameter introduced in C# 4.0. It allows you to neglect the parameters that have some predefined default values.
4. Differentiate between Boxing and Unboxing.
When a value type is converted to an object type, the process is known as boxing; whereas, when an object type is converted to a value type, the process is known as unboxing.
Boxing and unboxing enable value types to be treated as objects. Boxing a value type packages it inside an instance of the Object reference type. This allows the value type to be stored on the garbage collected heap. Unboxing extracts the value type from the object.
5. Explain the basic features of OOPs.
The following are the four basic features of OOP:
- Abstraction – Refers to the process of exposing only the relevant and essential data to the users without showing unnecessary information.
- Polymorphism – Allows you to use an entity in multiple forms.
- Encapsulation – Prevents the data from unwanted access by binding of code and data in a single unit called object.
- Inheritance – Promotes the reusability of code and eliminates the use of redundant code. It is the property through which a child class obtains all the features defined in its parent class. When a class inherits the common properties of another class, the class inheriting the properties is called a derived class and the class that allows inheritance of its common properties is called a base class.
6. What are collections and generics?
A collection can be defined as a group of related items that can be referred to as a single unit. The System.Collections namespace provides you with many classes and interfaces. Some of them are – ArrayList, List, Stack, ICollection, IEnumerable, and IDictionary. Generics provide the type-safety to your class at the compile time. While creating a data structure, you never need to specify the data type at the time of declaration. The System.Collections.Generic namespace contains all the generic collections.
7. How is method overriding different from method overloading?
Overriding involves the creation of two or more methods with the same name and same signature in different classes (one of them should be parent class and other should be child).
Overloading is a concept of using a method at different places with same name and different signatures within the same class.
8. What is a delegate?
A delegate is similar to a class that is used for storing the reference to a method and invoking that method at runtime, as required. A delegate can hold the reference of only those methods whose signatures are same as that of the delegate. Some of the examples of delegates are type-safe functions, pointers, or callbacks.
9. What is a DataReader object?
The DataReader object helps in retrieving the data from a database in a forward-only, read-only mode. The base class for all the DataReader objects is the DbDataReader class.
The DataReader object is returned as a result of calling the ExecuteReader() method of the Commandobject. The DataReader object enables faster retrieval of data from databases and enhances the performance of .NET applications by providing rapid data access speed. However, it is less preferred as compared to the DataAdapter object because the DataReader object needs an Open connection till it completes reading all the rows of the specified table.
An Open connection to read data from large tables consumes most of the system resources. When multiple client applications simultaneously access a database by using the DataReader object, the performance of data retrieval and other related processes is substantially reduced. In such a case, the database might refuse connections to other .NET applications until other clients free the resources.
10. AD0.NET consists of two fundamental components
- The DataSet, which is disconnected from the data source and does not need to know where the data that it holds is retrieved from.
- The .net data provider, which allows you to connect your application to the data source and execute the SQL commands against it.
The data provider contains the Connection, Command, DataReader, and DataAdapter objects. The Connection object provides connectivity to the database. The Command object provides access to database commands to retrieve and manipulate data in a database. The DataReader object retrieves data from the database in the readonly and forward-only mode. The DataAdapter object uses Command objects to execute SQL commands. The DataAdapter object loads the DataSet object with data and also updates changes that you have made to the data in the DataSet object back to the database.
11. What is ASP.NET?
ASP.NET is a specification developed by Microsoft to create dynamic Web applications, Web sites, and Web services. It is a part of .NET Framework. You can create ASP.NET applications in most of the .NET compatible languages, such as Visual Basic, C#, and J#. The ASP.NET compiles the Web pages and provides much better performance than scripting languages, such as VBScript. The Web Forms support to create powerful forms-based Web pages. You can use ASP.NET Web server controls to create interactive Web applications. With the help of Web server controls, you can easily create a Web application.
12. What is Query String? What are its advantages and limitations?
The Query String helps in sending the page information to the server. The Query String has the following advantages:
- Every browser works with Query Strings.
- It does not require server resources and so does not exert any kind of burden on the server.
The following are the limitations of Query String:
- Information must be within the limit because URL does not support many characters.
- Information is clearly visible to the user, which leads to security threats.
13. What is the difference between authentication and authorization?
Authentication verifies the identity of a user and authorization is a process where you can check whether or not the identity has access rights to the system. In other words, you can say that authentication is a procedure of getting some credentials from the users and verify the user’s identity against those credentials. Authorization is a procedure of granting access of particular resources to an authenticated user. You should note that authentication always takes place before authorization.
14. What is ViewState?
The ViewState is a feature used by ASP.NET Web page to store the value of a page and its controls just before posting the page. Once the page is posted, the first task by the page processing is to restore the ViewState to get the values of the controls.
15. Describe the complete lifecycle of a Web page.
When we execute a Web page, it passes from the following stages, which are collectively known as Web page lifecycle:
- Page request – During this stage, ASP.NET makes sure the page either parsed or compiled and a cached version of the page can be sent in response
- Start – During this stage sets the Request and Response page properties and the page check the page request is either a postback or a new request
- Page Initialization – During this stage, the page initialize and the control’s Unique Id property are set
- Load – During this stage, if the request is postback, the control properties are loaded without loading the view state and control state otherwise loads the view state
- Validation – During this stage, the controls are validated
- Postback event handling – During this stage, if the request is a postback, handles the event
- Rendering – During this stage, the page invokes the Render method to each control for return the output
- Unload – During this stage, when the page is completely rendered and sent to the client, the page is unloaded.