Interview Questions

100 Asp.net Interview Questions and Answers

What is the practical difference between store procedure and function??? Please Explain it in detail technically….???
Store Procedure Function
1)Store Procedure takes input, output parameters. 1)Function only takes input parameter.
2)A store Procedure may return non or more values. 2)A function always return one value either scalar or a table
3)Store Procedure cannot used in queries and expressions 3)Function can be used in queries and expression.
4) procedure can be called independently by execute command 5)Function are called from within Sql statement
6) In Exception can be handled in store procedure by Try-catch block 4)Try-catch cannot used be used in a function(error handling)
5)Store stored procedures we can use those statements. 6)We cannot use insert,delete,update and create statements in functions
7) you can not join Store Procedure 7)You can join UDF(User Define Function)
8) can be used to change server configuration 8)Can not be used to change server configuration

Differnce between data reader or dataset…Plese provide technical detail of these steps:-
Data reader:-
1)Read only approach
2)Faster access of data
3) forward only approach
4)Used to store single record
5)Bind with single control
6)connected approach
7)It is light weight
8)Less momory occupy

Dataset:-
1) Read/write approach
2) slower access in data
3) forward/backward approach
4)Used to store single or multiple table
5)Bind with multiple control
6)Disconnected approach
7)It is heavy weight
8)More memory occupy

string uid, password;
uid = userid;
password = password;
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(“http://ubaid.tk/sms/sms.aspx?uid” + uid + “&pwd=” + password + “&msg=” + message + “&phone=” + no + “&provider=way2sms”);
HttpWebResponse myResp = (HttpWebResponse)myReq.GetResponse();
System.IO.StreamReader respStreamReader = new System.IO.StreamReader(myResp.GetResponseStream());
stringresponseString = respStreamReader.ReadToEnd();
respStreamReader.Close();
myResp.Close();

What is Encapsulation?

Encapsulation – is the ability of an object to hide its data and methods from the rest of the world. It is one of the fundamental principles of OOPs.

Say we create a class, named Calculations. This class may contain a few members in the form of properties, events, fields or methods. Once the class is created, we may instantiate the class by creating an object out of it. The object acts as an instance of this class, the members of the class are not exposed to the outer world directly, rather, they are encapsulated by the class.

Example:
Public class Calculations
{
private void fnMultiply(int x, int y)
{
return x * y;
}
}


Calculations obj;
int Result;
Result = obj.fnMultiply(5,10);

What is inheritance?

Inheritance – is the concept of passing the traits of a class to another class.

A class comprises of a collection of types of encapsulated instance variables and types of methods, events, properties, possibly with implementation of those types together with a constructor function that can be used to create objects of the class. A class is a cohesive package that comprises of a particular kind of compile-time metadata. A Class describes the rules by which objects behave; these objects are referred to as “instances” of that class. (Reference)

Classes can inherit from another class. This is accomplished by putting a colon after the class name when declaring the class, and naming the class to inherit from—the base class—after the colon.

What is polymorphism?

Polymorphism means allowing a single definition to be used with different types of data (specifically, different classes of objects). For example, a polymorphic function definition can replace several type-specific ones, and a single polymorphic operator can act in expressions of various types. Many programming languages implement some forms of polymorphism.

The concept of polymorphism applies to data types in addition to functions. A function that can evaluate to and be applied to values of different types is known as a polymorphic function. A data type that contains elements of different types is known as a polymorphic data type.

Polymorphism may be achieved by overloading a function, overloading an operator, changing the order of types, changing the types using the same name for the member in context.

Example:
Public Class Calc
{
public void fnMultiply(int x, int y)
{ return x * y; }
public void fnMultiply(int x, int y, int z)
{ return x * y * z; }
}


Calc obj;
int Result;
Result = obj.fnMultiply(2,3,4); // The second fnMultiply would be called
Result = obj.fnMultiply(3,4); // The first fnMultiply would be called
//Here, the call depends on the number of parameters passed, polymorphism is achieved using overloading

What is a property? What is an event?

Property – A property is a thing that describes the features of an object. A property is a piece of data contained within a class that has an exposed interface for reading/writing. Looking at this definition, we might think we could declare a public variable in a class and call it a property. While this assumption is somewhat valid, the real technical term for a public variable in a class is a field. The main difference between a field and a property is in the inclusion of an interface.

We make use of Get and Set keywords while working with properties. We prefix the variables used within this code block with an underscore. Value is a keyword, that holds the value which is being retrieved or set.ss=”a”>

Private _Color As String
Public Property Color()
Get
Return _Color
End Get
Set(ByVal Value)
_Color = Value
End Set
End Property

Event – An action that an object does. When something happens, we say an event has happened. For example, when a button is clicked, we say it is the click( ) event. When a mouse hovers on an image, we say the mouseover( ) event has taken place.

What is an access modifier? What are the different types of Access modifiers?

Access Modifiers – Keywords used to change the way members of a class are accessed. The main purpose of using access specifiers is to provide security to the applications. The availability (scope) of the member objects of a class may be controlled using access specifiers.

What is Overloading? What is Overloads? What is Overload?

Overloading – is the concept of using one function or class in different ways by changing the signature of its parameters. We can define a function with multiple signatures without using the keyword Overloads, but if you use the Overloads keyword in one, you must use it in all of the function’s Overloaded signatures.

The Overloads keyword is used in VB.NET, while the Overload keyword is used in C# (There is no other difference). The Overloads property allows a function to be described using deferent combinations of parameters. Each combination is considered a signature, thereby uniquely defining an instance of the method being defined.

Overloading is a way through which polymorphism is achieved.

What is shared keyword used for? What is static?

Shared and Static mean the same. Shared is used in VB.NET, while Static is used in C#.

What is the virtual keyword used for?

Virtual – If a base class method is to be overriden, it is defined using the keyword virtual (otherwise the sealed keyword is used to prevent overriding).
Note that the class member method may be overriden even if the virtual keyword is not used, but its usage makes the code more transparent & meaningful. In VB.NET, we may use the
overridable keyword for this purpose.

When the override keyword is used to override the virtual method, in a scenario where the base class method is required in a child class along with the overriden method, then the base keyword may be used to access the parent class member. The following code example will make the usage more clear.

public class Employee
{
public virtual void SetBasic(float money) //This method may be overriden
{ Basic += money; }
}

public class Manager : Employee
{
public override void SetBasic(float money) //This method is being overriden
{
float managerIncentive = 10000;
base.SetSalary(money + managerIncentive); //Calling base class method
}
}

Explain overridable, overrides, notoverridable,mustoverride

These keywords are used in VB.NET.

Overridable -The Overridable keyword is used when defining a property or method of an inherited class, as overridable by the inheriting class.

Overides – The Overides keyword allows the inheriting class to disregard the property or method of the inherited class and implements ts own code.

NotOverridable – The NotOverridable keyword explicitly declares a property or method as not overridable by an inheriting class, and all properties are “not overridable” by default. The only real advantage to using this keyword is to make your code more readable.

MustOverride – The MustOverride keyword forces the inheriting class to implement its own code for the property or method

 

 

 

What is shadowing? Explain shadows keyword

Shadowing – is a concept of altering the behavior of a base class member

What is a constructor? Explain the New Keyword. What is a Private Constructor?

Constructor – A constructor is a function with the same name as that of the class. The Default Constructor of a class is without an argument. The default constructor ensures that every member data is initialized to a default value. Constructors provide a way for classes to initialize a state for their members. Note that constructors dont have a return type(not even void).

public SomeClass()
{
Console.Writeline(“Vishal says, Default Constructor is called”);
}
\
public SomeClass(string str)
{
Console.Writeline(“Vishal says, Custom Constructor is called” + str);
}

When a custom constructor is defined, the Default Constructor is not called. A constructor may also be overloaded.

New – This keyword may be used as a modifier and as an operator. When used as an operator, it creates an object on a heap to invoke constructors. When used an a modifier, it hides an inherited member from the base class member.

As an operator, it can be used to create an object and then to invoke the constructor of the class. See example below.

Example
SomeClass objSomeClass = new SomeClass(); //Creating a class object and invoking its constructor

float amount = new float(); //Creating an object of the type, and invoking its constructor

As a modifier, it is used to explicitly hide a member from the base class. See example.

Example
public class MamaClass
{
public void SomeMethod() { … }
}

public class BabyClass : MamaClass
{
new public void SomeMethod() { …. }
}

Private Constructor – When a constructor is created with a private specifier, it is not possible for other classes to derive from this class, neither is it possible to create an instance of this class. They are usually used in classes that contain static members only. It is also used to create Singleton classes.

What is a static constructor?

Static Constructor – It is a special type of constructor, introduced with C#. It gets called before the creation of the first object of a class(probably at the time of loading an assembly). See example below.

Example:
public class SomeClass()
{
static SomeClass()
{
//Static members may be accessed from here
//Code for Initialization
}
}

While creating a static constructor, a few things need to be kept in mind:
* There is no access modifier require to define a static constructor
* There may be only one static constructor in a class
* The static constructor may not have any parameters
* This constructor may only access the static members of the class
* We may create more than one static constructor for a class

Can a class be created without a constructor?
No. In case we dont define the constructor, the class will access the no-argument constructor from its base class. The compiler will make this happen during compilation.

 

What is Serialization? What is serializable attribute used for?

Serialization – The process of converting an object into a stream of bytes. This stream of bytes can be persisted. Deserialization is an opposite process, which involves converting a stream of bytes into an object. Serialization is used usually during remoting (while transporting objects) and to persist file objecst & database objects.

.NET provides 2 ways for serializtion 1) XmlSerializer and 2) BinaryFormatter/SoapFormatter

The XmlSerializer is used for Web Services. The BinaryFormatter & SoapFormatter is used for Remoting. While using XmlSerializer, it is required that the target class has parameter less constructors, has public read-write properties and has fields that can be serialized. The XmlSerializer has good support for XML documents. It can be used to construct objects from existing XML documents. The XmlSerializer enables us to serialize and deserialize objects to an XML format.

SoapFormatter enables us to serialize & deserialize objects to SOAP format. They can serialize private and public fields of a class. The target class must be marked with the Serializable attribute. On deserialization, the constructor of the new object is not invoked.

The BinaryFormatter has the same features as the SoapFormatter except that it formats data into binary format. The BinaryForamatter (and the SoapFormatter) has two main methods. Serialize and Deserialize. To serialize an object, we pass an instance of the stream and the object to the Serialize method. To Deserialize an object, you pass an instance of a stream to the Deserialize method.

You can use the BinaryFormatter to serialize many, but not all, classes in the .NET Framework. For example, you can serialize ArrayLists, DataSets, and Arrays but not other objects, such as DataReaders or TextBox controls. To serialize a class, the class must have the Serializable attribute or implement the ISerializable interface.

Note that the XmlSerializer captures only the public members of the class, whereas the BinaryFormatter & the SoapFormatter captures both the public & private members of the class. The output using the BinaryFormatter is quite compact, as the information is in binary format, whereas the XmlSerializer format is filled with XML tags. See example below…

Imports System.IO
Imports System.Runtime.Serialization.Formatters.Binary
Dim colArrayList As ArrayListDim
objFileStream As FileStreamDim
objBinaryFormatter As BinaryFormattercolArrayList = New ArrayList()
colArrayList.Add( “Whisky”)
colArrayList.Add( “Vodka”)
colArrayList.Add( “Brandy”)
objFileStream = New FileStream(MapPath(“C:\myArrayList.data”), FileMode.Create)
objBinaryFormatter = New BinaryFormatterobjBinaryFormatter.Serialize(objFileStream, colArrayList)objFileStream.Close()

Here we see that an instance of the file stream (objFileStream) and an instance of the object (colArrayList) is passed to the Serialize method of the BinaryFormatter object (objBinaryFormatter). We also end up creating a file by the name myArrayList.data on our hard-drive.In order to deserialize an object, see the code below…

Dim colArrayList As ArrayListDim objFileStream As FileStreamDim
objBinaryFormatter As BinaryFormatterDim strItem As String
objFileStream = New FileStream( MapPath(“myArrayList.data”), FileMode.Open )
objBinaryFormatter = New BinaryFormatter
colArrayList = CType( objBinaryFormatter.Deserialize( objFileStream ), ArrayList )
objFileStream.Close()
For Each strItem In colArrayList
Response.Write( ”  ” & strItem )
Next

Here, CType takes in two parameters, the first parameter is the serialized object in the file stream format, and the second parameter is the desired type. Finally, the page iterates through all the elements of the ArrayList and displays the value of each element.

XmlSerializer does not serialize instances of classes like Hashtable which implement the IDictionary interface.

Serializable – This is a class attribute. When we use this attribute with a class, an instance of this class can be taken in whatever state it is, and write it to a disk. The class can then be deserialized, and the class will act as if it is simply stored in the memory.

 

What is a delegate? What is a Multicast Delegate?

Delegate – It is a type safe function pointer. It is a type that holds the reference of a method. A delegate may be used to call a method asynchronously.

Multicast Delegate – it is a delegate that holds reference of more than one method. Multicast Delegates must have a return type of void.

What is an abstract class?

If a class is to serve the purpose of providing common fields and members to all subclasses, we create an Abstract class. For creating an abstract class, we make use of the abstract keyword. Such a class cannot be instantiated.

What is an interface? How to implement an interface?

An Interface is a collection of semantically related abstract members. An interface expresses through the members it defines, the behaviors that a class needs to support. An interface is defined using the keyword interface. The members defined in an interface contain only definition, no implementation. The members of an interface are all public by default, any other access specifier cannot be used.

An interface is implemented using implements keyword. A class may implement more than one keyword.

When a class inherits and implements at the same time, the inherited parent
class name is written first, followed by the names of the interfaces to be implemented.

Is multiple inheritance possible in .NET?

No. Multiple inheritance is not possible in .NET. This means it is not possible for one class to inherit from multiple classes. However, a class may implement multiple interfaces. We may also declare objects of different classes in a class. This way, the encapsulated class may be instantiated in other classes

Compare Response.Redirect(), Response.RedirectPermanent() and Server.Transfer().

 

The points below explain each one of these methods:

  • Response.Redirect() – Search Engine will take this redirection as Temporary(Status 302) and always keep the old page in its cache.

  • Response.RedirectPermanent() – Search Engine will take this a permanent redirection(Status 301) and will remove the old page from its cache/database and include new page for better performance on search.

  • Server.Transfer() – Search Engine will be unaware of any redirection that took place (Status 200) and will keep old page in its cache/database. It will think that the old page is producing the output response of the new page

What is ADO.NET?

ADO.NET is a part of the Microsoft .NET Framework. This framework provides the set of classes that deal with data communication between various layers of the software architecture and the database. It provides a continious access to different data source types such as SQL Server versions 7, 2000, 2005. It also provides connectivity options to data sources through OLE DB and XML. Connectivity may be established with other databases like Oracle, MySQL etc. as well.

ADO.NET has the ability to separate data access mechanisms, data manipulation mechanisms and data connectivity mechanisms.

ADO.NET introduces along with it the disconnected architecture. In a disconncted architecture, data may be stored in a DataSet. It contains providers for connecting to databases, commands for execution and retrieval of results.

The classes for ADO.NET are stored in the DLL System.Data.dll

What is a connection object in ADO.NET? How to connect to a database in .Net?

A Connection object in ADO.NET is used to establish a connection between a program (the program may be a windows page, a web page, a windows service, a web service etc.) and the database. The connection is open just long enough to get or update data. By quickly opening, then closing a connection, the server resources are used as little as possible. See code below on how to open a connection between UI and database…

‘Code below in VB.NET …
Dim objectConn as SqlClient.SqlConnection
Dim strConn as String
Try
‘First, create a connection object
objectConn=New SqlClient.SqlConnection()

‘Next, build the Connection String
strConn &=”Data Source=(local
strConn &=”Initial Catalog=DatabaseName;”
strConn &= “User ID=admin;”
strConn &= “Password=;”

‘Note here that the connection string may also be passed as a parameter
‘to the connection string object during instantiation

objectConn.ConnectionString = strConn
objectConn.Open() ‘Open the Connection

‘The connection is now open
‘Write your vb.net code here for operations on the database
objectConn.Close()

Catch Ex As Exception
MessageBox.Show(Ex.Message)
End Try

CONNECTION STRINGS FOR ACCESS, SQL 2000, SQL 2005, Oracle, MySQL

What are Connection Strings- A connection string has a group of semi-colon-separated attributes. Every .Net Data Provider connection string looks different, depending on the type of .NET Data Provider you need to use and which attributes are set for each different type of database system. An example, the connection string below is an example of what you use to connect to a local SQL Server. See that every parameter is separated by a semicolon.

Data Source=(local);Initial Catalog=Northwind;User ID=sa;Password=;

The connection string shown below is an example of how to connect to a Microsoft Access 2000 database using the OleDbConnection object in System.Data.OleDb.

Provider=Microsoft.Jet.OleDb.4.0;Data Source=C:\Northwind.mdb

Parameters in a Connection String – The parameters depend on the data provider is being used.

Server – The name of the SQL Server to which connection has to be established through ADO.NET. This is the name of the system that is running SQL server. We may use “local” or “localhost” for local computer. In case we are using named instances of SQL server, then the parameter would contain the computer name, followed by a backslash, followed by a named instance of the SQL server.

Database – The name of the database to which connection is to be established.

User ID – A user ID configured in the SQL Server by the SQL Server administrator.

Password – As the attribute name suggests, this is the password associated with the user id.

Note that connection string may also contain the Windows NT account security settings. This is done by passing the paramater “integrated security=true”

What is a command object in ADO.NET How to use a command object in .NET?

ADO.NET Command Object – The Command object is similar to the old ADO command object. It is used to store SQL statements that need to be executed against a data source. The Command object can execute SELECT statements, INSERT, UPDATE, or DELETE statements, stored procedures, or any other statement understood by the database. See sample code

‘Code below in VB.NET …
Dim ObjCom as SqlClient.SqlCommand
ObjCom.SqlConnection(strCon)
ObjCom.Connection.Open()
ObjCom.CommandText = “Select * from tblSample”
ObjCom.ExecuteNonQuery()

SqlCommand objects are not used much when we use datasets and data adapters. Following are some properties of the SqlCommand class…

Connection Property – This property contains data about the connection string. It must be set on the SqlCommand object before it is executed. For the command to execute properly, the connection must be open at the time of execution.

CommandText Property – This property specifies the SQL string or the Stored Procedure.

objCom.CommandText = “Insert into Employees (empid, empname) values (‘EMI0334′,’Mandy’)”

Paramaters Collection – If we want to update values in the Employees table above, but we do not know the values at design time, we make use of placeholders. These are variables prefixed with “@” symbol. Our code will look like this…

objCom.CommandText = “Insert into Employees (empid, empname) values (@empid, @empname)

Next, we have to create parameters that will be used to insert values into the placeholders. For this, we need to add parameters to the parameters collection of the SqlCommand object. This is done so that the values added through the parameters collection & placeholders get i ncluded in the SQL statement. Here, parameters mean the parameters to be passed to the SQL statement/Stored Procedures, not the method’s parameters.

In order to add parameters to the SqlCommand object, we write the following code…

objCom.CommandText = “Insert into Employees (empid, empname) values (@empid, @empname)”

objCom.Parameters.Add(“@empID”, txtempid.text)

objCom.Parameters.Add(“@empname”, txtempname.text)

ExecuteNonQuery Method – Once the connection is open, we run the query in the SqlCommand object using the ExecuteNonQuery method. This is very simple as shown below…

objConnection.Open()
objCom.ExecuteNonQuery()
objConnection.Close()

What is SelectCommand in ADO.NET?

Select Command Property – This property is used to hold the SQL command that is used to retrieve data from the data source. The CommandText and Connection are properties of the Select Command propety. CommandType is also a property of Select Command. See example below…

Dim da as new SqlDataAdapter
da.SelectCommand = New SqlCommand( )
With da.SelectCommand
.Connection = objConnection
.CommandText = “select * from employees”
End With

What is a DataView in ADO.NET?

DataView – Just like we have Views in SQL (in our backend), we have DataView object in ADO.NET. A dataview object represents bindable, customized view of a DataTable object. Operations like Sorting, Filtering, Searching, Editing and Navigation may be performed on a DataView object. In scenarios like retrieval of a subset of data from a Datatable, we may make use of DataViews to get this data. Note that the DefaultView property of a DataTable returns the Default data view for the DataTable. In case a custom view of a DataTable has to be created on a DataView, then the RowFilter property of the DataView is set to the DefaultView.

A dataview may also be used to sort data that resides in it in ascending or descending order. Below is code on how to sort data in a dataview in ascending or descending order…

DataView objdv = new DataView();
objdv.Sort(“ColumnName Asc|Desc”);

What is a Typed Dataset in ADO.NET? Why do we use a Typed DataSet? What is the difference between a Typed and an UnTyped DataSet?

Typed DataSet – When a created DataSet derives from the DataSet class, that applies the information contained in the XSD to create a Typed class, this DataSet is said to be a Typed Dataset. Information from the schema whic comprises the tables, columns, and rows is created and compiled to a new DataSet derived from the XSD. The Typed DataSet class features all functionality of the DataSet class. This may be used with methods that take an instance of the DataSet class as a parameter.

Note that an UnTyped DataSet does not have any schema. It is exposed simply as a mere collection.

How to create a Typed DataSet?
Write click your project in the Solution Explorer.
Click Add New Item.
Select DataSet.

This adds a new XSD to the project. The schema created may be viewed as an XML. When this xsd file is compiled, two files are created by Visual Studio. The first file that contains the .vb or .cs extension contains the information about the proxy class. This class contains methods & properties that are required to access the database data. The second file has an extension xsx and this contains information about the layout of the XSD.

What is CLR in .NET?

Common Language Runtime – It is the implementation of CLI. The core runtime engine in the Microsoft .NET Framework for executing applications. The common language runtime supplies managed code with services such as cross-language integration, code access security, object lifetime management, resouce management, type safety, pre-emptive threading, metadata services (type reflection), and debugging and profiling support. The ASP.NET Framework and Internet Explorer are examples of hosting CLR.

The CLR is a multi-language execution environment. There are currently over 15 compilers being built by Microsoft and other companies that produce code that will execute in the CLR.

The CLR is described as the “execution engine” of .NET. It’s this CLR that manages the execution of programs. It provides the environment within which the programs run. The software version of .NET is actually the CLR version.

When the .NET program is compiled, the output of the compiler is not an executable file but a file that contains a special type of code called the Microsoft Intermediate Language (MSIL, now called CIL, Common Intermediate Language). This MSIL defines a set of portable instructions that are independent of any specific CPU. It’s the job of the CLR to translate this Intermediate code into a executable code when the program is executed making the program to run in any environment for which the CLR is implemented. And that’s how the .NET Framework achieves Portability. This MSIL is turned into executable code using a JIT (Just In Time) complier. The process goes like this, when .NET programs are executed, the CLR activates the JIT complier. The JIT complier converts MSIL into native code on a demand basis as each part of the program is needed. Thus the program executes as a native code even though it is compiled into MSIL making the program to run as fast as it would if it is compiled to native code but achieves the portability benefits of MSIL.

What is a Join in SQL? What are different types of Joins in SQL? Outer Join, Inner Join, Equi Join, Natural Join, Cross Join, Full Outer Join

Join
A join in SQL is a clause that allows merging of records from one or more than one tables in a database. The records from the tables are fetched based on some values that are common to each. See code example below:

Say we have 2 tables, T_EMPLOYEES and T_SALARY

Select * from T_EMPLOYEES JOIN T_SALARY
ON
T_EMPLOYEES.EMP_ID = T_SALARY.EMP_ID;

Consider the following 2 tables:

T_SHOOTERS

Name

Gun_Type

Ballu Balram

1

Ekgoli Shikari

2

Fauji Bhai

3

Thulla

4

Jackal

4

T_GUNTYPES

Gun_Type

Description

1

Katta Pt. 5

2

Desi Bandook Single Barrel

3

Rocket Launcher

4

Colt

 

Inner Join – in this type of join, every record in the tables being joined have a matching record. The condition based on which the records are matched is called the join predicate.

Implicit Vs. Explicit Inner Joins – When the clause ‘Inner Join’ is used, it is said to be an explicit join.
See code example below:

SELECT * FROM t_shooters
INNER JOIN t_guntypes
ON t_shooters.gun_type = t_guntypes.gun_type;

Above is an explicit inner join. The same can be achieved without using the ‘inner join’ clause like this:

SELECT * FROM t_shooter, t_guntype
WHERE t_shooters.gun_type = t_guntypes.gun_type;

Above is an implicit inner join.

Equi Join – This is a type of Inner Join. (It is also called a Theta Join). – It is a join where the equality ‘=‘ operator is used. In case an operator like ‘<‘ or ‘>’ or any other operator is used, it is not an Equi Join.

An Equi Join may be used by using equality operator or the Using clause. See code example below:

SELECT T_SHOOTERS.NAME, GUN_TYPE, T_GUNTYPES.DESCRIPTION
FROM T_SHOOTERS INNER JOIN T_GUNTYPES
USING(GUN_TYPE);

Natural Join – It is a type of Inner Join. It is a join where in the join predicate is based on all the column names that are common to both the tables being joined. See code example below:

SELECT * From T_SHOOTERS NATURAL JOIN T_GUNTYPES;

Results will be as below:

Gun_Type

T_Shooters.Name

T_Guntypes.Description

1

Ballu Balram

Katta Pt. 5

2

Ekgoli Shikari

Desi Bandook Single Barrel

3

Fauji Bhai

Rocket Launcher

4

Thulla

Colt

5

Jackal

Colt

Cross Join – Also called Cartesian Join. It is the result of joining each row of a table with each row of the other table.

Outer Join – In an Outer join, each record of a table does not really need to match with a record in the corresponding table. Outer joins maybe Left Outer Joins or Right Outher Joins. Outer Joins are always explicit.

Left Outer Join – This join contains all records from the left table, and matching records in the other table. However, if there are no matching records in the other table, it will still return a result, where in the records of the other table will be NULL.

Right Outer Join – This join fetches all records from the right table and only matching records from the left table. By saying left table, it means the table who’s name is to the left of the Join Clause.

See code example below:

SELECT * FROM t_shooters LEFT OUTER JOIN t_guntypes
ON t_shooters.gun_type = t_guntypes.gun_type;

Full Outer Join – A full outer join merges the result fetched from Left and Right Outer joins. See code example below:

SELECT * FROM t_shooters
FULL OUTER JOIN t_guntypes
ON t_shooters.gun_type = t_guntypes.gun_type;

SQL Queries  SQL  Create Table  DDL, Create, Alter, Drop commands  DML, Select, Insert, Update, Delete  Create Database  ACID Rules  Dual Table  NULL  Join, Inner, Outer, Left, Right, Full, Cartesian, Natural, Equi  Table, View and a Synonym?  Execute  Function  Stored

What is the difference between a Table, View and Synonym in SQL?

A Table is a repository of data, where in the table itself is a physical entity. The table resides physically in the database.

A View is not a part of the database’s physical representation. It is precompiled, so that data retrieval behaves faster, and also provide a secure accessibility mechanism.

See code example below:

Create table T_EMPLOYEE
(Emp_Id integer primary key,
Name varchar2(50)
Skillset varchar2(200),
Salary number(12,2),
DOB datetime);

Say there is a scenario where Salary is not to be shown to a group of users, a View may be created to display allowable information:

Create view EMP_SOME_DETAILS
as
(Select Emp_Id, Name, Skillset, DOB
From T_EMPLOYEE);

The advantages of using a view are as follows:
– It may access data from a table, multiple tables, view, multiple views, or a combination of these
– A view connects to the data of its base table(s).
– Provides a secure mechanism of data accessibility

Synonym is alternate name assigned to a table, view, sequence or program unit.
– It may be used to shadow the original name and owner of the actual entity
– Extends the reach of tables, by allowing public access to the synonym

What are DDL statements in SQL? Explain the Create, Alter and Drop commands.

In SQL, DDL stands for Data Definition Language. It is the part of SQL programming language that deals with the construction and alteration of database structures like tables, views, and further the entities inside these tables like columns. It may be used to set the properties of columns as well.

The three popular commands used in DDL are:
Create – Used to create tables, views, and also used to create functions, stored procedures, triggers, indexes etc.

— An example of Create command below
CREATE TABLE t_students (
stud_id NUMBER(10) PRIMARY KEY,
first_name VARCHAR2(20) NULL,
last_name VARCHAR2(20) NOT NULL,
dateofbirth DATE NULL);

Drop – Used to totally eliminate a table, view, index from a database – which means that the records as well as the total structure is eliminated from the database.

— An example of Drop command below
DROP TABLE t_students;

Alter – Used to alter or in other words, change the structure of a table, view, index. This is particularly used when there is a scenario wherein the properties of fields inside a table, view, index are supposed to be updated.

— An example of Alter command below
ALTER TABLE t_students ADD address VARCHAR2(200); — adds a column ALTER TABLE t_students DROP COLUMN dateofbirth; — drops a column ALTER TABLE t_students MODIFY COLUMN address VARCHAR2(100); — drops a column

— You can also modify multiple columns using a single modify clause ALTER TABLE t_students MODIFY
{
COLUMN address VARCHAR2(100)
COLUMN first_name VARCHAR2(50)
COLUMN last_name VARCHAR2(50)
};

— You can also add constraints like NOT NULL using the Modify statement
ALTER TABLE t_students Modify
{ first_name VARCHAR2(50) NOT NULL };

 

What are DML commands in SQL? Select, Insert, Update, Delete?

DML
stands for Data Manipulation Language, its the part of SQL that deals with querying, updating, deleting and inseting records in tables, views.

The following types of actions may be performed using DML commands:

1) Select – This command is used to fetch a result set of records from a table, view or a group of tables, views by making use of SQL joins.

Retrieval of data using SQL statements can be done by using different predicates along with it like
Where
Group By
Having
Order By

— The simplest example of a select statement where in a user wants to
— retrieve all the records of a table, can be performed by using ‘*’
— Use an asterisk character to retrieve all records of a table
SELECT * FROM t_students

The Where clause is used with DML statements to check for a condition being met in row.

SELECT * FROM t_students where age > 12 and age < 16;

— Another way
SELECT * FROM t_students where age between 12 and 16;

SELECT * FROM t_students where name like ‘R%’
— Query above uses the like predicate along with a wildcard
— The result will retrieve all names starting with character ‘R’

The Group By statement in SQL is used for aggregation, which means that the result that is returned is based on grouping of results based on a column aggregation.

SELECT Roll_No, SUM(Marks) FROM t_students
WHERE Class = 5
GROUP BY Roll_No

The Having statement in SQL makes sure that an SQL SELECT statement should only return rows where aggregate values match conditions that are stated.

SELECT student_id, SUM(Marks) FROM t_students
WHERE Admission_Date = ’01-Apr-2009′
GROUP BY student_id
HAVING SUM(Marks) > 500

The Order By clause in SQL is used to set the sequence of the output in terms of being alphabetical, magnitude of size, order of date. It may accompanied by an ‘asc’ or ‘desc’ clause so as to specify whether the results are in ascending or descending order. Note: The results of a select query that does not use asc or desc is in ascending order, by default.

SELECT fname, lname FROM t_students ORDER BY fname ASC;

2) Insert – This command is used to add record(s) to a table. While inserting a record using the insert statement, the number of records being entered should match the columns of the table. In case the number of items being entered are less than the number of columns, in that case the field names also need to be specified along with the insert statement. See code example below:

Consider a table named t_employees with the following fields:
Emp_Id, FirstName, LastName, Height, Weight
The syntax to insert a record in this table will be:

INSERT INTO T_EMPLOYEES VALUES (‘445′,’Amitabh’,’Bachan’,’6ft’,’85kg’);

What if not all the items need to be insert? Do the following:

INSERT INTO T_EMPLOYEES (Emp_Id, FirstName, Height)
VALUES (‘445′,’Amitabh’,’6ft’);

Further, an Insert statement can also be used in combination with Select statement. What we can do is that the result of the Select statement may be used as the values to be inserted in a table. See code example below:

INSERT INTO T_EMPLOYEES
SELECT * FROM T_SOME_OTHER_EMPLOYEE_TABLE
WHERE FirstName IN (‘Pappu’, ‘Ramu’,’Kallu’,’Gabbar’);

You may even insert specific columns like below:

INSERT INTO T_EMPLOYEES (Emp_Id, FirstName)
SELECT Emp_Id, FirstName FROM T_SOME_OTHER_EMPLOYEE_TABLE
WHERE FirstName IN (‘Mogambo’, ‘Dr. Dang’,’Shakaal’,’Gabbar’,’Ajgar Jurraat’,’Bhaktawar’,’Bad Man’, ‘Prem’,’Billa Jilani’);

3) Update – This command is used to edit the record(s) of a table. It may be used to update a single row based on a condition, all rows, or a set of rows based on a condition.

It is used along with the set clause. Optionally, a where clause may be used to match conditions. See code example below:

UPDATE TABLE T_EMPLOYEES SET FIRSTNAME = ‘Anthony’
WHERE EMP_ID = ‘445’;

More examples below:

Update the value of a column

UPDATE TABLE T_EMPLOYEES SET AGE = AGE + 1;

Update multiple columns in one statement

UPDATE TABLE T_SALARY SET
BONUS = BONUS + 10000,
BASIC = BASIC + (0.2 * BONUS);

4) Delete – This command is used to remove record(s) from a table. All records may be removed in one go, or a set of records may be deleted based on a condition. See code example below:

DELETE FROM T_VILLAINS WHERE FIRSTNAME = ‘Pappu’;

Code below deletes record(s) based on a condition

DELETE FROM T_VILLAINS WHERE AGE < 18 ;

Delete may also be done based on the result of a sub query:

DELETE FROM T_VILLAINS WHERE AGE IN
(SELECT AGE FROM T_VILLAINS WHERE AGE < 18)

What are generics in C#?

Generics in C# is a new innovative feature through which classes and methods in C# may be designed in such a way that the rules of a type are not followed until it is declared. The generics feature in C# has been introduced with version 2.0 of the .NET Framework. Using generics, a class template may be declared that may follow any type as required at runtime. The class behavior is later governed by the type that we pass to the class. Once the type is passed, the class behaves depending on the type passed to this generic class

Whats the difference between Classic ASP and ASP.NET?

Major difference: Classic ASP is Interpreted. ASP.NET is Compiled. If code is changed, ASP.NET recompiles, otherwise does’nt.
Other differences: ASP works with VB as the language. ASP.NET works with VB.NET & C# as the languages (Also supported by other languages that run on the .NET Framework).
ASP.NET is the web technology that comes with the Microsoft .NET Framework. The main process in ASP.NET is called aspnet_wp.exe that accesses system resources. ASP.NET was launched in 2002 with version 1.0. Subsequent versions are 1.1 and version 2.0. ASP.NET is built up using thousands of objects, ordered in the System namespace. When an ASP.NET class is compiled, its called an assembly.
In Classic ASP, complex functionalities are achieved using COM components, that are nothing but component objects created using VB 6, C++ etc, and are usually in a DLL format. These components provide an exposed interface to methods in them, to the objects that reference these components. Last version of classic ASP is version 3.0. ASP has 7 main objects – Application, ASPError, ObjectContext, Request, Response, Server, Session.

What is the difference between abstract class and interface?

If a class is to serve the purpose of providing common fields and members to all subclasses, we create an Abstract class. For creating an abstract class, we make use of the abstract keyword. Such a class cannot be instantiated. Syntax below:

abstract public class Vehicle { }

Above, an abstract class named Vehicle has been defined. We may use the fields, properties and member functions defined within this abstract class to create child classes like Car, Truck, Bike etc. that inherit the features defined within the abstract class. To prevent directly creating an instance of the class Vehicle, we make use of the abstract keyword. To use the definitions defined in the abstract class, the child class inherits from the abstract class, and then instances of the Child class may be easily created.
Further, we may define abstract methods within an abstract class (analogous to C++ pure virtual functions) when we wish to define a method that does not have any default implementation. Its then in the hands of the descendant class to provide the details of the method. There may be any number of abstract methods in an abstract class. We define an abstract method using the abstract keyword. If we do not use the abstract keyword, and use the virtual keyword instead, we may provide an implementation of the method that can be used by the child class, but this is not an abstract method.
Remember, abstract class can have an abstract method, that does not have any implementation, for which we use the abstract keyword, OR the abstract class may have a virtual method, that can have an implementation, and can be overriden in the child class as well, using the override keyword. Read example below

Example: Abstract Class with Abstract method
namespace Automobiles
{
public abstract class Vehicle
{
public abstract void Speed() //No Implementation here, only definition
}
}

Example: Abstract Class with Virtual method
namespace Automobiles
{
public abstract class Vehicle
{
public virtual void Speed() //Can have an implementation, that may be overriden in child class
{

}
}

Public class Car : Vehicle
{
Public override void Speed()
//Here, we override whatever implementation is there in the abstract class
{
//Child class implementation of the method Speed()
}
}
}

An Interface is a collection of semantically related abstract members. An interface expresses through the members it defines, the behaviors that a class needs to support. An interface is defined using the keyword interface. The members defined in an interface contain only definition, no implementation. The members of an interface are all public by default, any other access specifier cannot be used. See code below:

Public interface IVehicle //As a convention, an interface is prefixed by letter I
{
Boolean HasFourWheels()
}

Time to discuss the Difference between Abstract Class and Interface

1) A class may inherit only one abstract class, but may implement multiple number of Interfaces. Say a class named Car needs to inherit some basic features of a vehicle, it may inherit from an Aabstract class named Vehicle. A car may be of any kind, it may be a vintage car, a sedan, a coupe, or a racing car. For these kind of requirements, say a car needs to have only two seats (means it is a coupe), then the class Car needs to implement a member field from an interface, that we make, say ICoupe.
2) Members of an abstract class may have any access modifier, but members of an interface are public by default, and cant have any other access modifier.
3) Abstract class methods may OR may not have an implementation, while methods in an Interface only have a definition, no implementation.

 

What is the difference between Server.Transfer and Response.Redirect?

Both “Server” and “Response” are objects of ASP.NET. Server.Transfer and Response.Redirect both are used to transfer a user from one page to another. But there is an underlying difference.

//Usage of Server.Transfer & Response.Redirect
Server.Transfer(“Page2.aspx”);
Response.Redirect(“Page2.aspx”);

The Response.Redirect statement sends a command back to the browser to request the next page from the server. This extra round-trip is often inefficient and unnecessary, but this established standard works very well. By the time Page2 is requested, Page1 has been flushed from the server’s memory and no information can be retrieved about it unless the developer explicitly saved the information using some technique like session, cookie, application, cache etc.

The more efficient Server.Transfer method simply renders the next page to the browser without an extra round trip. Variables can stay in scope and Page2 can read properties directly from Page1 because it’s still in memory. This technique would be ideal if it wasn’t for the fact that the browser is never notified that the page has changed. Therefore, the address bar in the browser will still show “Page1.aspx” even though the Server.Transfer statement actually caused Page2.aspx to be rendered instead. This may occasionally be a good thing from a security perspective, it often causes problems related to the browser being out of touch with the server. Say, the user reloads the page, the browser will request Page1.aspx instead of the true page (Page2.aspx) that they were viewing. In most cases, Response.Redirect and Server.Transfer can be used interchangeably. But in some cases, efficiency or usability may be the deciding factor in choosing

What is the difference between Server.Transfer and Server.Execute?

Both Server.Transfer and Server.Execute were introduced in Classic ASP 3.0 (and still work in ASP.NET).

When Server.Execute is used, a URL is passed to it as a parameter, and the control moves to this new page. Execution of code happens on the new page. Once code execution gets over, the control returns to the initial page, just after where it was called. However, in the case of Server.Transfer, it works very much the same, the difference being the execution stops at the new page itself (means the control is’nt returned to the calling page).

In both the cases, the URL in the browser remains the first page url (does’nt refresh to the new page URL) as the browser is’nt requested to do so

What is the difference between ExecuteScalar and ExecuteNonQuery?
What is ExecuteReader?

ExecuteScalar – Returns only one value after execution of the query. It returns the first field in the first row. This is very light-weight and is perfect when all your query asks for is one item. This would be excellent for receiving a count of records (Select Count(*)) in an sql statement, or for any query where only one specific field in one column is required.

ExecuteNonQuery – This method returns no data at all. It is used majorly with Inserts and Updates of tables. It is used for execution of DML commands.

Example:
SqlCommand cmd = new SqlCommand(“Insert Into t_SomeTable Values(‘1′,’2’)”,con);
//note that con is the connection object
con.Open();
cmd.ExecuteNonQuery(); //The SQL Insert Statement gets executed

ExecuteReader – This method returns a DataReader which is filled with the data that is retrieved using the command object. This is known as a forward-only retrieval of records. It uses our SQL statement to read through the table from the first to the last record.

Whats the difference between MSIL and CIL?

MSIL is the name given to the intermediate language in .NET Framework Beta, 1.0 and 1.1. From version 2.0 onwards, the intermediate language is called CIL. We can say, MSIL is the old name. MSIL stands for Microsoft Intermediate Language. CIL stands for Common Intermediate Language. Its actually a low level human readable language implementation of CLI.

There is not much difference between the two. Compilers like vbc.exe and csc.exe compile the code into intermediate language. CIL is the name submitted by Microsoft to the European Computer Manufacturer’s Association(ECMA) as a standard.

Q1. Explain the differences between Server-side and Client-side code?
Ans. Server side code will execute at server (where the website is hosted) end, & all the business logic will execute at server end where as client side code will execute at client side (usually written in javascript, vbscript, jscript) at browser end.

DML

DML is abbreviation of Data Manipulation Language. It is used to retrieve, store, modify, delete, insert and update data in database.

SELECT – Retrieves data from a table
INSERT –  Inserts data into a table
UPDATE – Updates existing data into a table
DELETE – Deletes all records from a table

DDL

DDL is abbreviation of Data Definition Language. It is used to create and modify the structure of database objects in database.

CREATE – Creates objects in the database
ALTER – Alters objects of the database
DROP – Deletes objects of the database
TRUNCATE – Deletes all records from a table and resets table identity to initial value.

DCL

DCL is abbreviation of Data Control Language. It is used to create roles, permissions, and referential integrity as well it is used to control access to database by securing it.

GRANT – Gives user’s access privileges to database
REVOKE – Withdraws user’s access privileges to database given with the GRANT command

TCL

TCL is abbreviation of Transactional Control Language. It is used to manage different transactions occurring within a database.

COMMIT – Saves work done in transactions
ROLLBACK – Restores database to original state since the last COMMIT command in transactions
SAVE TRANSACTION – Sets a savepoint within a transaction

What is cursor?

A cursor is a set of rows together with a pointer that identifies a current row. 

What is Linq?

LINQ or Language-Integrated Query is such a tool. LINQ is set of extensions to the .Net Framework 3.5 and its managed languages that sets the query as an object. It defines a common syntax and a programming model to query different types of data using a common language.

.InsertOnSubmit()

 

Q2. What type of code (server or client) is found in a Code-Behind class?

Ans. Server side code.

Q3. How to make sure that value is entered in an asp:Textbox control?
Ans. Use a RequiredFieldValidator control.

Q4. Which property of a validation control is used to associate it with a server control on that page?
Ans. ControlToValidate property.

Q5. How would you implement inheritance using VB.NET & C#?

Ans. C# Derived Class : Baseclass
VB.NEt : Derived Class Inherits Baseclass

Q6. Which method is invoked on the DataAdapter control to load the generated dataset with data?
Ans. Fill() method.

Q7. What method is used to explicitly kill a user’s session?

Ans. Session.Abandon()

Q8. What property within the asp:gridview control is changed to bind columns manually?
Ans. Autogenerated columns is set to false

Q9. Which method is used to redirect the user to another page without performing a round trip to the client?

Ans. Server.Transfer method

.

Q10. How do we use different versions of private assemblies in same application without re-build?
Ans.Inside the Assemblyinfo.cs or Assemblyinfo.vb file, we need to specify assembly version.
assembly: AssemblyVersion

Q11. Is it possible to debug java-script in .NET IDE? If yes, how?

Ans. Yes, simply write “debugger” statement at the point where the breakpoint needs to be set within the javascript code and also enable javascript debugging in the browser property settings.

Q12. How many ways can we maintain the state of a page?

Ans. 1. Client Side – Query string, hidden variables, viewstate, cookies
2. Server side – application , cache, context, session, database

Q13. What is the use of a multicast delegate?

Ans. A multicast delegate may be used to call more than one method.

Q14. What is the use of a private constructor?

Ans. A private constructor may be used to prevent the creation of an instance for a class.

Q15. What is the use of Singleton pattern?

Ans. A Singleton pattern .is used to make sure that only one instance of a class exists.

Q16. When do we use a DOM parser and when do we use a SAX parser?

Ans. The DOM Approach is useful for small documents in which the program needs to process a large portion of the document whereas the SAX approach is useful for large documents in which the program only needs to process a small portion of the document.

Q17. Will the finally block be executed if an exception has not occurred?

Ans.Yes it will execute.

Q18. What is a Dataset?

Ans. A dataset is an in memory database kindof object that can hold database information in a disconnected environment.

Q19. Is XML a case-sensitive markup language?

Ans. Yes.

Q20. What is an .ashx file?
Ans. It is a web handler file that produces output to be consumed by an xml consumer client (rather than a browser)

Q21. What is encapsulation?

Ans. Encapsulation is the OOPs concept of binding the attributes and behaviors in a class, hiding the implementation of the class and exposing the functionality.

Q22. What is Overloading?
Ans. When we add a new method with the same name in a same/derived class but with different number/types of parameters, the concept is called overluoad and this ultimately implements Polymorphism.

Q23. What is Overriding?

Ans. When we need to provide different implementation in a child class than the one provided by base class, we define the same method with same signatures in the child class and this is called overriding.

Q24. What is a Delegate?

Ans. A delegate is a strongly typed function pointer object that encapsulates a reference to a method, and so the function that needs to be invoked may be called at runtime.

Q25. Is String a Reference Type or Value Type in .NET?

Ans. String is a Reference Type object.

Q26. What is a Satellite Assembly?

Ans. Satellite assemblies contain resource files corresponding to a locale (Culture + Language) and these assemblies are used in deploying an application globally for different languages.

Q27. What are the different types of assemblies and what is their use?

Ans. Private, Public(also called shared) and Satellite Assemblies.

Q28. Are MSIL and CIL the same thing?

Ans. Yes, CIL is the new name for MSIL.

Q29. What is the base class of all web forms?

Ans. System.Web.UI.Page

Q30. How to add a client side event to a server control?

Ans. Example… BtnSubmit.Attributes.Add(“onclick”,”javascript:fnSomeFunctionInJavascript()”);

Q31. How to register a client side script from code-behind?
Ans. Use the Page.RegisterClientScriptBlock method in the server side code to register the script that may be built using a StringBuilder.

Q32. Can a single .NET DLL contain multiple classes?
Ans. Yes, a single .NET DLL may contain any number of classes within it.

Q33. What is DLL Hell?
Ans. DLL Hell is the name given to the problem of old unmanaged DLL’s due to which there was a possibility of version conflict among the DLLs.

Q34. can we put a break statement in a finally block?
Ans. The finally block cannot have the break, continue, return and goto statements.

Q35. What is a CompositeControl in .NET?
Ans. CompositeControl is an abstract class in .NET that is inherited by those web controls that contain child controls within them.

Q36. Which control in asp.net is used to display data from an xml file and then displayed using XSLT?
Ans. Use the asp:Xml control and set its DocumentSource property for associating an xml file, and set its TransformSource property to set the xml control’s xsl file for the XSLT transformation.

Q37. Can we run ASP.NET 1.1 application and ASP.NET 2.0 application on the same computer?
Ans. Yes, though changes in the IIS in the properties for the site have to be made during deployment of each.

Q38. What are the new features in .NET 2.0?
Ans. Plenty of new controls, Generics, anonymous methods, partial classes, iterators, property visibility (separate visibility for get and set) and static classes.

Q39. Can we pop a MessageBox in a web application?
Ans. Yes, though this is done clientside using an alert, prompt or confirm or by opening a new web page that looks like a messagebox.

Q40. What is managed data?
Ans. The data for which the memory management is taken care by .Net runtime’s garbage collector, and this includes tasks for allocation de-allocation.

Q41. How to instruct the garbage collector to collect unreferenced data?
Ans. We may call the garbage collector to collect unreferenced data by executing the System.GC.Collect() method.

Q42. How can we set the Focus on a control in ASP.NET?
Ans. txtBox123.Focus(); OR Page.SetFocus(NameOfControl);

Q43. What are Partial Classes in Asp.Net 2.0?
Ans. In .NET 2.0, a class definition may be split into multiple physical files but partial classes do not make any difference to the compiler as during compile time, the compiler groups all the partial classes and treats them as a single class.

Q44. How to set the default button on a Web Form?
Ans. <asp:form id=”form1″ runat=”server” defaultbutton=”btnGo”/>

Q45.Can we force the garbage collector to run?
Ans. Yes, using the System.GC.Collect(), the garbage collector is forced to run in case required to do so.

Q46. What is Boxing and Unboxing?
Ans. Boxing is the process where any value type can be implicitly converted to a reference type object while Unboxing is the opposite of boxing process where the reference type is converted to a value type.

Q47. What is Code Access security? What is CAS in .NET?
Ans. CAS is the feature of the .NET security model that determines whether an application or a piece of code is permitted to run and decide the resources it can use while running.

Q48. What is Multi-tasking?
Ans. It is a feature of operating systems through which multiple programs may run on the operating system at the same time, just like a scenario where a Notepad, a Calculator and the Control Panel are open at the same time.

Q49. What is Multi-threading?
Ans. When an application performs different tasks at the same time, the application is said to exhibit multithreading as several threads of a process are running.2

Q50. What is a Thread?
Ans. A thread is an activity started by a process and its the basic unit to which an operating system allocates processor resources.

Q51. What does AddressOf in VB.NET operator do?
Ans. The AddressOf operator is used in VB.NET to create a delegate object to a method in order to point to it.

Q52. How to refer to the current thread of a method in .NET?
Ans. In order to refer to the current thread in .NET, the Thread.CurrentThread method can be used. It is a public static property.

Q53. How to pause the execution of a thread in .NET?
Ans. The thread execution can be paused by invoking the Thread.Sleep(IntegerValue) method where IntegerValue is an integer that determines the milliseconds time frame for which the thread in context has to sleep.

Q54. How can we force a thread to sleep for an infinite period?
Ans. Call the Thread.Interupt() method.

Q55. What is Suspend and Resume in .NET Threading?
Ans. Just like a song may be paused and played using a music player, a thread may be paused using Thread.Suspend method and may be started again using the Thread.Resume method. Note that sleep method immediately forces the thread to sleep whereas the suspend method waits for the thread to be in a persistable position before pausing its activity.

Q56. How can we prevent a deadlock in .Net threading?
Ans. Using methods like Monitoring, Interlocked classes, Wait handles, Event raising from between threads, using the ThreadState property.

Q57. What is Ajax?
Ans. Asyncronous Javascript and XML – Ajax is a combination of client side technologies that sets up asynchronous communication between the user interface and the web server so that partial page rendering occur instead of complete page postbacks.

Q58. What is XmlHttpRequest in Ajax?
Ans. It is an object in Javascript that allows the browser to communicate to a web server asynchronously without making a postback.

Q59. What are the different modes of storing an ASP.NET session?
Ans. InProc (the session state is stored in the memory space of the Aspnet_wp.exe process but the session information is lost when IIS reboots), StateServer (the Session state is serialized and stored in a separate process call Viewstate is an object in .NET that automatically persists control setting values across the multiple requests for the same page and it is internally maintained as a hidden field on the web page though its hashed for security reasons.

Q60. What is a delegate in .NET?
Ans. A delegate in .NET is a class that can have a reference to a method, and this class has a signature that can refer only those methods that have a signature which complies with the class..

Q61. Is a delegate a type-safe functions pointer?
Ans. Yes

Q62. What is the return type of an event in .NET?
Ans. There is No return type of an event in .NET.

Q63. Is it possible to specify an access specifier to an event in .NET?
Ans. Yes, though they are public by default.

Q64. Is it possible to create a shared event in .NET?
Ans. Yes, but shared events may only be raised by shared methods.

Q65. How to prevent overriding of a class in .NET?
Ans. Use the keyword NotOverridable in VB.NET and sealed in C#.

Q66. How to prevent inheritance of a class in .NET?
Ans. Use the keyword NotInheritable in VB.NET and sealed in C#.

Q67. What is the purpose of the MustInherit keyword in VB.NET?
Ans. MustInherit keyword in VB.NET is used to create an abstract class.

Q68. What is the access modifier of a member function of in an Interface created in .NET?
Ans. It is always public, we cant use any other modifier other than the public modifier for the member functions of an Interface.

Q69. What does the virtual keyword in C# mean?
Ans. The virtual keyword signifies that the method and property may be overridden.

Q70. How to create a new unique ID for a control?
Ans. ControlName.ID = “ControlName” + Guid.NewGuid().ToString(); //Make use of the Guid class

Q71A. What is a HashTable in .NET?
Ans. A Hashtable is an object that implements the IDictionary interface, and can be used to store key value pairs. The key may be used as the index to access the values for that index.

Q71B. What is an ArrayList in .NET?
Ans. Arraylist object is used to store a list of values in the form of a list, such that the size of the arraylist can be increased and decreased dynamically, and moreover, it may hold items of different types. Items in an arraylist may be accessed using an index.

Q72. What is the value of the first item in an Enum? 0 or 1?
Ans. 0

Q73. Can we achieve operator overloading in VB.NET?
Ans. Yes, it is supported in the .NET 2.0 version, the “operator” keyword is used.

Q74. What is the use of Finalize method in .NET?
Ans. .NET Garbage collector performs all the clean up activity of the managed objects, and so the finalize method is usually used to free up the unmanaged objects like File objects, Windows API objects, Database connection objects, COM objects etc.

Q75. How do you save all the data in a dataset in .NET?
Ans. Use the AcceptChanges method which commits all the changes made to the dataset since last time Acceptchanges was performed.

Q76. Is there a way to suppress the finalize process inside the garbage collector forcibly in .NET?
Ans. Use the GC.SuppressFinalize() method.

Q77. What is the use of the dispose() method in .NET?
Ans. The Dispose method in .NET belongs to IDisposable interface and it is best used to release unmanaged objects like File objects, Windows API objects, Database connection objects, COM objects etc from the memory. Its performance is better than the finalize() method.

Q78. Is it possible to have have different access modifiers on the get and set methods of a property in .NET?
Ans. No we can not have different modifiers of a common property, which means that if the access modifier of a property’s get method is protected, and it must be protected for the set method as well.

Q79. In .NET, is it possible for two catch blocks to be executed in one go?
Ans. This is NOT possible because once the correct catch block is executed then the code flow goes to the finally block.

Q80. Is there any difference between System.String and System.StringBuilder classes?
Ans. System.String is immutable by nature whereas System.StringBuilder can have a mutable string in which plenty of processes may be performed.

Q81. What technique is used to figure out that the page request is a postback?
Ans. The IsPostBack property of the page object may be used to check whether the page request is a postback or not. IsPostBack property is of the type Boolean.

Q82. Which event of the ASP.NET page life cycle completely loads all the controls on the web page?
Ans. The Page_load event of the ASP.NET page life cycle assures that all controls are completely loaded. Even though the controls are also accessible in Page_Init event but here, the viewstate is incomplete.

Q83. How is ViewState information persisted across postbacks in an ASP.NET webpage?
Ans. Using HTML Hidden Fields, ASP.NET creates a hidden field with an ID=”__VIEWSTATE” and the value of the page’s viewstate is encoded (hashed) for security.

Q84. What is the ValidationSummary control in ASP.NET used for?
Ans. The ValidationSummary control in ASP.NET displays summary of all the current validation errors.

Q85. What is AutoPostBack feature in ASP.NET?
Ans. In case it is required for a server side control to postback when any of its event is triggered, then the AutoPostBack property of this control is set to true.

Q86. What is the difference between Web.config and Machine.Config in .NET?
Ans. Web.config file is used to make the settings to a web application, whereas Machine.config file is used to make settings to all ASP.NET applications on a server(the server machine).

Q87. What is the difference between a session object and an application object?
Ans. A session object can persist information between HTTP requests for a particular user, whereas an application object can be used globally for all the users.

Q88. Which control has a faster performance, Repeater or Datalist?
Ans. Repeater.

Q89. Which control has a faster performance, Datagrid or Datalist?
Ans. Datalist.

Q90. How to we add customized columns in a Gridview in ASP.NET?
Ans. Make use of the TemplateField column.

Q91. Is it possible to stop the clientside validation of an entire page?
Ans. Set Page.Validate = false;

Q92. Is it possible to disable client side script in validators?
Ans. Yes. simply EnableClientScript = false.

Q93. How do we enable tracing in .NET applications?
Ans. <%@ Page Trace=”true” %>

Q94. How to kill a user session in ASP.NET?
Ans. Use the Session.abandon() method.

Q95. Is it possible to perform forms authentication with cookies disabled on a browser?
Ans. Yes, it is possible.

Q96. What are the steps to use a checkbox in a gridview?
Ans. <ItemTemplate>
<asp:CheckBox id=”CheckBox1″ runat=”server” AutoPostBack=”True”
OnCheckedChanged=”Check_Clicked”></asp:CheckBox>
</ItemTemplate>

Q97. What are design patterns in .NET?
Ans. A Design pattern is a repeatitive solution to a repeatitive problem in the design of a software architecture.

Q98. What is difference between dataset and datareader in ADO.NET?
Ans. A DataReader provides a forward-only and read-only access to data, while the DataSet object can carry more than one table and at the same time hold the relationships between the tables. Also note that a DataReader is used in a connected architecture whereas a Dataset is used in a disconnected architecture.

Q99. Can connection strings be stored in web.config?
Ans. Yes, in fact this is the best place to store the connection string information.

Q100. Whats the difference between web.config and app.config?
Ans. Web.config is used for web based asp.net applications whereas app.config is used for windows based applications.

1 thought on “100 Asp.net Interview Questions and Answers”

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.