Archive

Archive for March, 2013

Difference between Class and Structure

March 6, 2013 Leave a comment

Classes are Reference types and Structures are Values types.

Classes are reference types, basically they will contain the address of an instance variables.

Class SimpleClass
{
Public int Value; 	
}

This the simple class am assigning value to Object to it.

Static Public void Main (string [] arg)
{
SimpleClass objSimpleClass1=new SimpleClass();
objSimpleClass1.Value=5;
SimpleClass objSimpleClass2= new SimpeClass();
objSimpleClass2.Value=10;
}

objSimpleClass1.Value=5

after in next step we change it to 10 in the object objSimpleClass2.  Since both object refer the same address, changes happened in the objSimpleClass2 or in last step that value will reflect in other object also.


		
Advertisements
Categories: C#

What is Boxing and UnBoxing

March 5, 2013 Leave a comment

Converting a value type to reference type is called Boxing.

Example:

int i = 12;
object box = i;

Converting a reference type to value type is called UnBoxing.

Example:

object box = 12;
int i = (int)box;

Difference Between StringBuilder and String

March 5, 2013 Leave a comment

 

String:

While concatenate two strings, a new copy in the memory will be created and old string object will be deleted this called ‘IMMUTABLE’. Normally the performance will be slow.
StringBuilder:

 

Normally we use Append() to concatenate the string. combining two string will be take place existing string object. No new memory will be created for this stringBuilder object and its more efficient.

 

 

Categories: C# Tags: , ,

Enabling and disabling Session

March 2, 2013 Leave a comment

To Optimize the performance once can enable or disable the session in

1) Page Level
2) Application Level

At Page level set the EnableSessionState =”False” in page directive, it will disable the
session activity.

To access the session but not allow to writing data set EnableSessionState =”ReadOnly”

To disable the session in application level, configer the web.config as below

<system.Web>
<Pages enableSessionState=”false”>
</system.Web>

Session State Modes in ASP.NET

March 2, 2013 Leave a comment

Normally You will configure the session in Web.Config or in code behind. In web config session state is configured with the the element <Sessionstate>. In that there are lot of attribute are there like Mode, Timeout, StateConnectionString, CustomProvider, cookieless, cookieName,allowCustomSqlDatabase,useHostingIdentity etc…

ASP.NET session state supports several storage options for session variables and identified
as session-state Mode.

1) Custom
2) InProc
3) Off
4) SQLServer
5) StateServer

The default sessionMode=’InProc’.
a) InProc mode:- which stores session state in memory on the Web server. This is the default.

Note:- If you enable Web-garden mode by setting the webGarden attribute to true in the processModel element of the application’s Web.config file, do not use InProcsession state mode. If you do, data loss can occur if different requests for the same session are served by different worker processes.

b) StateServer mode:- which stores session state in a process, referred to as the ASP.NET state service, that is separate from the ASP.NET worker process or IIS application pool. Using this mode ensures that session state is preserved if the Web application is restarted and also makes session state available to multiple Web servers in a Web farm

c) SQLServer mode:- stores session state in a SQL Server database. This ensures that session state is preserved if the Web application is restarted and also makes session state available to multiple Web servers in a Web farm. To use SQLServer mode, you must first be sure the ASP.NET session state database is installed on SQL Server. You can install the ASP.NET session state database using the Aspnet_regsql.exe tool

d) Custom mode:- which enables you to specify a custom storage provider.

e) Off mode:- which disables session state.

More about:- SesionMode Clickhere

Session Event in ASP.NET

March 2, 2013 Leave a comment

There are two types of session events available in ASP.NET:

1) Session_Start
2) Session_End

You can find or handle the above two events in global.asax file. Session_Start event will trigger when ever new session start. Similarly Session_End event trigger when a session is abandoned or expires.

Code to view ViewState information in ASP.NET

March 1, 2013 Leave a comment

It is advisable not to store critical information in ViewState, because it is not encrypted it encoded. To view the information of view state please use the below code.

string strDecodevalue=””;

string strEncodedValue=””; // Copy and past the viewstate encoded value from HTML page.
strDecodevalue = Encoding.ASCII.GetString(Convert.FromBase64String(strEncodedValue ));
MessageBox.Show(strDecodevalue);

%d bloggers like this: