Follow in Twitter & Facebook


Like in Facebook

Powered By Blogger Widgets

Free Download

FREE Tools


Monday, March 26, 2012

Static variables in C#.Net

Introduction:
Static variables are very important in C#.Net and you should use carefully in your Asp.Net application. So it is very important to know what are static variables in C#.Net. Also you can check very good article on Delegates in C#.net.

Description:
Static variables are classes variables not instance variables.

A static variable is a variable whose single copy in memory is shared by all objects,
so any modification to the static variable will modify it's value in all objects.

Static variable is a class variable which value remains constant for the entire class.
In Traditional ASP we had the application object to store the application wide variables.

But in .Net, we have Static variables which in most cases faster to acessing than Application object.

Inorder to implement the static variable , we first have to give our Global.asax a class name
by adding the directive
<%@ Application class name = "MyClass" %>

Then we specify our static variables inside the script tags using "public" or "shared" keywards.

<Script language = "C#" runat = "Server">

public static string mystaticvar = "xyz.com" ;

</Script>

Now we have the variable 'mystaticvar' setup, we can call it directly from our .aspx page using the class name and variable name.

X = Myclass.mystaticvar

Where Myclass--class name and mystaticvar--variable name.

Hope this article will help you all....

Also check Primary Key,Unique Key SQL Server 2008.




0 on: "Static variables in C#.Net"