QuestPond’s Interview Questions & Answers on .NET

What is a Class and structure’s?

Structures are value types and classes are reference types..

When to use Structures and When to use classes?

You will use structures when: –

Point 1:- If you want to represent a custom value type. This custom value type is derived from primitive data types (int, double). Some of the example’s of custom types are co-ordinates (which have X, Y), complex numbers (which have real and imaginary components). You can also term these things as value objects or technical objects. Technical objects do not represent real world objects like customer, supplier, invoice etc.

Point 2:- If you want to have low memory foot print. For instance let’s say you want to plot a graph. To plot a graph you need to have 100’s of objects created so that you can represent co-ordinates. Now if you create a class and generate those 100’s of objects you end up putting lot of load on your garbage collector. If you create a “struct” , it’s a value type. So they get created and destroyed immediately. Thus putting less load on memory.
For all other scenarios use a class.

datatype

 

What are similarities between Class and structure?

Following are the similarities between classes and structures:-

  • Both can have constructors, methods, properties, fields, constants, enumerations, events, and event handlers.
  • Structures and classes can implement interface.
  • Both of them can have constructors with and without parameter.
  • Both can have delegates and events.

What is the difference between Class and structure’s?

Following are the key differences between them:-

  • Structures are value types and classes are reference types. So structures use stack and classes use heap.
  • Structures members cannot be declared as protected, but class members can be. You cannot do inheritance in structures.
  • Structures do not require constructors while classes require.
  • Objects created from classes are terminated using Garbage collector. Structures are not destroyed using GC.

Click and see here for more basics training in .NET


 

Advertisements
Posted in Uncategorized | Tagged , , , , , , , | Leave a comment

QuestPond’s Interview Questions & Answers on ADO.NET

How is stored procedure different from functions?

  • Function cannot affect the state of the database which means we cannot perform CRUD operation on the database. Stored Procedure can affect the state of the database by using CRUD operations.
  • Store Procedure can return zero or n values whereas Function can return only one value.
  • Store Procedure can have input, output parameters for it whereas functions can have only input parameters.
  • Function can be called from Stored Procedure whereas Stored Procedure cannot be called from Function

How do we use stored procedure in ADO.NET and how do we provide parameters to the stored procedures?

ADO.NET provides the SqlCommand object, which provides the functionality of executing stored procedures. In the command type we need to provide the command type as stored procedure as shown in the below code snippet.

SqlCommand objCommand = new SqlCommand("sp_Insert", objConnection
;
objCommand.CommandType = CommandType.StoredProcedure;
objCommand.ExecuteNonQuery();

See following video on dataset is a disconnected while datareader is connected: –

 

Click and see here for more ADO.NET training.

Posted in Uncategorized | Tagged , , , , , , , , , | Leave a comment

ASP.NET Interview questions around Web.config

Can ASP.NET project run with out a Web.config file ?

Yes.

Can we have two Web.config file in a project ?

Yes we can , look at the below video which explain’s why we need two web.config files.

mockup

Differentiate between Web.config vs machine.config file

“Web.config” files apply settings to each web application, while “Machine.config” file apply settings for all ASP.NET applications running on that machine.

This question is taken from Shiv koirala’s ASP.NET Interview book. You can buy this book from http://www.flipkart.com/net-interview-questions-cd-rom-english-6th/p/itmdyuqzdqx8cvqx

Posted in Uncategorized | Tagged , , , , | Leave a comment

QuestPond’s Interview Questions & Answers on ASP.NET

How many types of validation controls are provided by ASP.NET?

There are six main types of validation controls:-

RequiredFieldValidator
It checks whether the control have any value. It is used when you want the control should not be empty.

RangeValidator
It checks if the value in validated control is in that specific range. Example TxtCustomerCode should not be more than eight lengths.

CompareValidator
It checks that the value in controls should match some specific value. Example Textbox TxtPie should be equal to 3.14.

RegularExpressionValidator
When we want the control, value should match with a specific regular expression.

CustomValidator
It is used to define User Defined validation.

Validation Summary
It displays summary of all current validation errors on an ASP.NET page.

How can we force all the validation control to run?

Page.Validate

How can we check if all the validation control are valid and proper?

Using the Page.IsValid() property you can check whether all the validation are done.

If client side validation is enabled, will server side code still run ?

When client side validation is enabled server emit’s JavaScript code for the custom validators. However, note that does not mean that server side checks on custom validators do not execute. It does this redundant check two times, as some of the validators do not support client side scripting.

Which JavaScript file is referenced for validating the validators at the client side?

WebUIValidation.js JavaScript file installed at “aspnet_client” root IIS directory is used to validate the validation controls at the client side

How to disable client side script in validators?

Set ‘EnableClientScript’ to false.

How can I show the entire validation error message in a message box on the client side?

In validation summary set “ShowMessageBox” to true.

See following video on implement ASP.NET Forms Authentication: –

 

Click and see here for more step by step learning ASP.NET.

Posted in Uncategorized | Tagged , , , , , , | Leave a comment

QuestPond’s Interview Questions & Answers on OOP(Object Oriented Programming) in .NET

What is operator overloading?

Operator overloading is a concept of polymorphism where you can redefine operators like +, – , * etc with additional functionalities.

For instance we can redefine the + functionalities to add objects like obj1 + obj2. Below is simple code snippet which redefines + operator.

class SomeClass
{

private int someValue;

public SomeClass(int val)
{
 someValue = val; 
}

public static SomeClass operator +(SomeClass arg1, SomeClass arg2)
{
return new SomeClass(arg1.someValue +  arg2.someValue);
}

}

You can now use the + operator to add objects of type someclass as shown in the below code snipet.

Obj = obj1 + obj2;

What are abstract classes?

Abstract class is a half defined parent class. The full implementation of abstract class is defined by the child classes.

For example below code snippet shows a simple abstract class / half defined class called “DatabaseCommon” and later the concrete classes i.e. “SQLServer” and “Oracle” inherit and define a complete implementation for the same.

To define an abstract class we need to use the abstract keyword.

public abstract class DatabaseCommon
{
}
public  class SQLServer : DatabaseCommon
{
}
public  class Oracle : DatabaseCommon
{
}

What are abstract methods?

Abstract classes can have abstract methods. Abstract methods when defined in a parent class have to be implemented in the child classes. If abstract methods are not implemented it will throw a error.

What is an Interface?

Interface is a contract that defines the signature of the functionality. It looks like a class but has no implementation. It has only empty definition of methods, functions, events, and indexer.

Interfaces provide forced implementation. For instance in the below code snippet we have created a simple interface called as “IDbCompulsory”. The below classes who implement interface “IDbCompulsory” has to provide implementation for “ExecSql”.

interface  IDbCompulsory
{
void ExecSql();
}
public  class SQLServer : IDbCompulsory
{
public void ExecSql()
{
// Here code for firing SQL Server SQL statements
// are written          
}
}
public  class Oracle : IDbCompulsory
{
public void ExecSql()
{
// Here code for firing Oracle SQL statements
// are written                      
}
}

See following video on difference between Abstraction and Encapsulation: –

 

Click and see here for more basic on OOP training in .NET.

 

 

 

 

 

 

Posted in Uncategorized | Tagged , , , , , , , , , , , , , | Leave a comment

QuestPond’s Interview Questions & Answers on encrypting web.config files in ASP.NET

Encryption can be done in ASP.NET using the “aspnet_regiis.exe” tool. There are two encryption options provided by ASP.NET: –

Windows Data Protection API (DPAPI) Provider (DataProtectionConfigurationProvider) – this provider uses the built-in cryptography capabilities of Windows to encrypt and decrypt the configuration sections. By default this provider uses the machine’s key.

RSA Protected Configuration Provider (RSAProtectedConfigurationProvider) – uses RSA public key encryption to encrypt/decrypt the configuration sections. With this provider you need to create key containers that hold the public and private keys used for encrypting and decrypting the configuration information.

While encrypting the config files we can choose what kind of provider we need for encryption. So let’s understand step by step how we can actually encrypt the web.config file sections.
Step 1:- Go to the command prompt of the framework.

Step 2:- Run the aspnet_regiis.exe as shown in the figure. We have provided the section which we need to encrypt and the provider. If the command is successfully executed, you should get a succeeded message of encryption. You can see we have decrypted the appSettings section. We have also shown how the unencrypted config file looks after running aspnet_regiis.exe.

Step 3:- Once the file is encrypted you can use the same in your program in a normal fashion. For instance the below defined appSetting key “MyValue” in figure “aspnet_regiis.exe in Action” can be displayed simply by:-

Response.Write(WebConfigurationManager.AppSettings("MyValue")
.ToString())

You do not need to do any kind if decryption inside your program again.

Figure 21.4 shows how the plain text is further changed to an encrypted form using aspnet_regiis.exe.

fig

Below is the aspnet_regiis in different forms for your referral.

-- Generic form for encrypting the Web.config file for a particular 
website...
aspnet_regiis.exe -pef section physical_directory –prov provider
   -- or --
aspnet_regiis.exe -pe section -app virtual_directory –prov provider

-- Concrete example of encrypting the Web.config file for a 
particular website

aspnet_regiis.exe -pef "connectionStrings" "C:\Inetpub\wwwroot\
MySite" –prov "DataProtectionConfigurationProvider"
   -- or --
aspnet_regiis.exe -pe "connectionStrings" -app "/MyWebSite" –prov "
DataProtectionConfigurationProvider"

-- Generic form for decrypting the Web.config file for a 
particular website...
aspnet_regiis.exe -pdf section physical_directory
   -- or --
aspnet_regiis.exe -pd section -app virtual_directory

-- Concrete example of decrypting the Web.config file for a 
particular website...
aspnet_regiis.exe -pdf "connectionStrings" "C:\Inetpub\wwwroot\
MyWebSite"
   -- or --
aspnet_regiis.exe -pd "connectionStrings" -app "/MyWebSite"

See following video on Web.config transformation: –

 

Click and see here for more training on ASP.NET.

 

 

Posted in Uncategorized | Tagged , , , , , , , , , | Leave a comment

QuestPond’s Interview Questions & Answers on learning Viewstate for state management, Hidden frames and Cookies in ASP.NET

What are benefits and Limitation of using Viewstate for state management?

Following are the benefits of using Viewstate:-

  • No server resources are required because state is in a structure in the page code.
  • Simplicity.
  • States are retained automatically.
  • The values in view state are hashed, compressed, and encoded, thus representing a higher state of security than hidden fields.
  • View state is good for caching data in Web frame configurations because the data is cached on the client.  

Following are limitation of using Viewstate:-

  • Page loading and posting performance decreases when large values are stored because view state is stored in the page.
  • Although view state stores data in a hashed format, it can still be tampered because it is stored in a hidden field on the page. The information in the hidden field can also be seen if the page output source is viewed directly, creating a potential security risk.

Below is sample of storing values in view state.

this.ViewState[“EnterTime”] = DateTime.Now.ToString();

How can you use Hidden frames to cache client data?

This technique is implemented by creating a Hidden frame in page which will contain your data to be cached.

<FRAMESET cols=”100%,*,*”>
<FRAMESET rows=”100%”>
<FRAME src=”data_of_frame1.html”></FRAMESET>
<FRAME src=”data_of_hidden_frame.html”>
<FRAME src=”data_of_hidden_frame.html” frameborder=”0″ noresize scrolling=”yes”>
</FRAMESET>  

Above is a sample of hidden frames where the first frame “data_of_frame1.html” is visible and the remaining frames are hidden by giving whole col section to first frame. 100 % is allocated to first frame and remaining frames thus remain hidden.

What are benefits and limitations of using Hidden frames?

Following are the benefits of using hidden frames:

  • You can cache more than one data field.
  • The ability to cache and access data items stored in different hidden forms.
  • The ability to access JScript® variable values stored in different frames if they come from the same site.  

The limitations of using hidden frames are:

  • Hidden frames are not supported on all browsers.
  • Hidden frames data can be tampered thus creating security hole.

What are benefits and limitations of using Cookies?

Following are benefits of using cookies for state management:-

  • No server resources are required as they are stored in client.
  • They are light weight and simple to use  

Following are limitation of using cookies:-

  • Most browsers place a 4096-byte limit on the size of a cookie, although support for 8192-byte cookies is becoming more common in the new browser and client-device versions available today.
  • Some users disable their browser or client device’s ability to receive cookies, thereby limiting the use of cookies.
  • Cookies can be tampered and thus creating a security hole.
  • Cookies can expire thus leading to inconsistency.

Below is sample code of implementing cookies

Request.Cookies.Add(New HttpCookie(“name”, “user1”))

See following video on importance of session and viewstate: –

 

Click and see here for more step by step learning on ASP.NET.


Posted in Uncategorized | Tagged , , , , , , , , , , , | Leave a comment