asp.net| variable | Static variables are a better choice than application to use static in asp.net
In the traditional ASP page, we need to use the application variable to pass some special variables, in the ASP.net any page can be a class, Global.asax is no exception.
We just need to add the class name to the Global.asax.
<%@ application Classname= "Myglobals"%>
Then we define a few static variables.
Using Shared in vb.net
Using Static in C #
Vb:
<script language= "VB" runat= "Server" >
Public Shared sgreeting as String = "Welcome"
</Script>
C#
<script language= "C #" runat= "Server" >
Public Static String sgreeting = "Welcome"
</Script>
Now we can use the class name on the other asp.net. The name of the variable can be quoted.
x = myglobals.sgreeting
Ok!
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service