global variable vs local variable

hi all,

i have a scenario like function is called more than 1000 times.in that function i declared a varible and assigning a value .i felt like declare a global varible use it in that function and assign value.which is best.please tell me in performance point of view.

thanks in advance

0
harish448
10/29/2008 4:53:33 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

2 Replies
999 Views

Similar Articles

[PageSpeed] 21

 Hai

 Good Morning 

you have call  the function  more than 1000 times

Better use Global variables, so you can call the function, anywhere.. it has good performance.

suppose it you want assign different values to the variables , whenever the function has been

called for that use local variables...


Regards,
M.Venkatesan
My Blog : http://venkat-dotnetsamples.blogspot.com


Please remember to click “Mark as Answer” on the post that helps you,and to click “Unmark as Answer” if a marked post does not actually answer your question.
0
venkatu2005
10/29/2008 5:56:07 AM

Hello,

Declare a variable as near to the place where you will be using them (local variables) unless you really want to use them throughout the scope of the class (in which case you will declare variables at class level).This means that within subroutines and methods, you should use local variables rather than global variables whenever possible. Local, in this case, means that the variables are defined between the sub/function and end sub/function statements. Within subroutines and functions, access to local variables is faster than to global variables. Plus, it makes for cleaner and more readable code and easier debugging.


Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
0
vinz
10/29/2008 6:07:35 AM
Reply:

Similar Artilces:

acessing variables across web forms( a la Global variable)
Hi, I have multiple web forms in my application i want to access some data( from sql database) which is common to all the forms. i want to retrieve the data only once & use it for all the forms. as ther are are no global variables in .net can anyone suggest how i can implement this ? lonewolf If the data is small enough, use the Session. It is like viewstate, but held on the server. To access it, do the following in the code behind: E.g Let's say you want to store login information, i.e. userid. Then... To set the variable (typically done on your login page): Dim useri...

local variable & global variable
Hello, please see below: script example> var myAge=20; var myName="Ann"; function MyInfo() { var yourAge = myAge + 13; var yourName = "John"; return yourAge; } : : Question : Where are global variable "myAge" and "myName" stored? And Where are local variable "yourAge" and "yourName" stored? They are stored in context area? ...

sub local variable changes global variable.
Hi all, I am passin a two-dimensional array to a sub and when the sub returns, the original array has changed. Eventually I want to pass the array into a recursive sub, so I want to find a way to circumvent this behaviour. Notice how my global is "@a" and the sub local is "@b" - Why is this happening - How can I properly pass a two dimensional array to a sub, without the array in main changing? Ideas anyone? Here is the minimal script to reproduce my finding: ============= #!/usr/bin/perl use warnings; use strict; sub try { my @b = @_; ...

Re:How to make a local variable a global variable in Perl
Hi I have this code: ........ sub MakeEth() { unless ($_Globals{NICIP_ADRESS}==$IPREAL[0]) { $_Globals{ETH_NETIF} eq "eth0"; } else{ $_Globals{ETH_NETIF} eq "eth0:1"; } } ........ sub StartDhcp() { my $_cmd = $_Os{$_Globals{OS}}{DHCPD} . " " . $_Globals{ETH_NETIF}; system($_cmd); } I wanted to make $_Globals{ETH_NETIF} affected by what it is in the scope MakeEth because in the sub StartDhcp $_Globals{ETH_NETIF} is undef I would to make it a variable glob...

Variable Variables
Hi, Maybe the solution is very simple, but how do I create variable variables in vb.net? I want to use the value of a variable as a part of the name of another variable. A very simple example below: code: Dim a As String a = "1" Label a.Text = "hi" page: <asp:Label id="Label1" runat="server">Label</asp:Label> In need this to change a range of values by using just one loop. I can´t do that without creating a variable variable name. Hi, check out this little demo application I created for you: ...

variable not a variable
Error:Must declare the variable '@cartDateTime'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Must declare the variable '@cartDateTime'. Dim connStr As SqlConnection            Dim cmdInsert As SqlCommand            Dim strInsert As String      &n...

variable variables?
Hello! How to make a variable receive an increment in the name? I want to do it for example: I have: Label1->Caption = "1"; Label2->Caption = "2"; Label3->Caption = "3"; Label4->Caption = "4"; And I want to do something like that: for (i=1; i<5; i++) { Label+i->Caption = i; } Any idea? Can I do something like that? Thanks and regards Alexandre Create a vector of pointers to the various objects. In your case below, construct a vector (called Labels) of pointers to TLable long enough to hold pointers to...

variable of variables
Say I have 2 scenarios and I want to use a different variable depending on which scenario applies without coding this logic. So I could have a database table t_variables which has: Scenario: Variable: --------- -------- 1 v_name 2 v_company In my Powerbuilder code I'd have values in v_name & v_company. What I'd like to be able to do is to select which variable to use from the table and assign that to something, e.g. select variable into v_variable from t_variables where scenario = 1 so at this point v_variable would be 'v_name'...

Global Variables vs. instance variables declared at application object level
There is only one application object instance during the application runtime that is instantiated at the start along with the global variables, so I am looking for what are the major differences, advantages , and disadvantages between Global Variables and instance variables declared for the application object. Thanks I've wondered also about the application instance variables. I think the difference with global vars is very subtle. Maybe too subtle to be of any use. Anyway, you shouldn't be using either one of them :-) Geert 'Darling' Van Damme Moh...

Response.Redirect with Session Variable vs. Global Variable -- Best Practices?
Hi,I have a simple contact form and when the user presses the submit button an email is sent and  I have a response.redirect to "emailSent.aspx" where it says "Your request has been received....etc.".  I have the submit button in a try/catch block.  What I want to do is a "emailFailed.aspx" where it says "Email problem, etc." but I also want to carry over the ex.message text.  I want to pass the ex.error text to the "emailFailed.aspx" page so on pageLoad I can have a label with something like:labelMessage.Text = "There was a problem with your email.  The error is " +...

Global variables / special variables / variable identifier with just one character
Expected error message: "Global symbol "$b" requires explicit package name". However, I get result: "test". I've checked the special variables and it looks like $b is one of these. use warnings; use strict; zzz ($b); print "$b\n"; sub zzz{ $_[0] = "test"; } Does it mean - that in general - we should not use one character variables in Perl? thanks adam ------=_NextPart_000_0011_01C4ADBA.05A29580 Content-Type: text/plain; charset="big5" Content-Transfer-Encoding: quoted-printable "Adam" &l...

Acessing variables, objects and functions from javascript to VB .NET Web Forms
I have included some javascript files in my vb.net application. I want to access the variables, objects and functions of Javascript to the VB.NET Web Forms, which means that I want to transfer the methods from Javascript to the code-behind in a web form. How do I do this? Can anybody help me with some sample codes...thanks in advance . you can't pass javascript variables (client side) to code-behind (server side). you can however put your variables into hidden input fields then access those input fields from code-behind. or use ajax I think the only way to do this is...

getdate() vs parameter vs local variable
I have a query within a stored proc that uses between logic ex. CREATE PROCEDURE dbo.sReport (@dEndDate SmallDateTime) AS Declare @v_dEndDate SmallDateTime select @v_dEndDate = @dEndDate --select 1 select iId from Contract where getdate() between dEffDate and dExpDate -- select 2 select iId from Contract where @v_dEndDate between dEffDate and dExpDate --select 3 select iId from Contract where @dEndDate between dEffDate and dExpDate If I pass in the current datetime to the proc the following happens. The query uses the same plan regardless of which select...

Acessing variables,arrays, objects and functions from javascript to VB .NET Web Forms
I have a textbox where user can put data.I store data into an array .I did this with java script.now i want to acess the array from the Codebehind  in vb.net web pages.here is the codefunction MakeArray( n ) { if( n <= 0 ) { this.length = 0; return this; } this.length = n; for( var i = 1; i <= n; i++ ) { this[ i ] = 0; } return this; } var Form1 = new MakeArray( 25 ); var index = 0; var cmmnd = 1; function f_store( sTR ) { var i; if( index >= Form1.length ) { for( i = 1; i < Form1.length; i++ ) Form1[i-1] = Form1; index = Form1.length - 1; } Form1[ index ] = cmmnd + ":" + sT...

Web resources about - global variable vs local variable - asp.net.web-forms

Variable - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Westpac interest rate rise is one of many variable loan rate rises
WESTPAC is not alone in hitting its owner-occupier customers with a surprise interest rate rise, as dozens of other variable rate home loans ...

Airbnb upgrades variable pricing tool for hosts
Online home rental group Airbnb is rolling out an upgraded variable pricing tool that automatically raises or cuts room rates based on supply ...

Commonwealth Bank raises variable home loan rates
Home owners' mortgage costs are set to rise by hundreds of dollars a year, after the Commonwealth Bank became the latest bank to hike interest ...

CBA lifts variable home loan rates to offset costs associated with stricter capital requirements
The Commonwealth Bank to lift its home loan interest rates independently of the Reserve Bank to partially offset costs associated with stricter ...

Washington Square Signs Spielbergs, Choi Joins Variable and More
... films and an episode of the HBO comedy series "Girls," on which he plays the role of Ray Ploshansky. New York-based creative collective Variable ...

YouTube v10.32 Tweaks Some Interface Elements And Includes Hints About Virtual Reality Content And Variable ...
Forget Update Wednesday! Monday is the new big day. Not only were we treated to the latest M preview release and the official Marshmallow name, ...

"You have to ignore many variables to think women are paid less than men. California is happy to try." ...
Writes Sarah Ketterer in The Wall Street Journal in "The ‘Wage Gap’ Myth That Won’t Die" (which you can get to without subscribing if you Google ...

Staley: 'A lot of different variables...been a hard year'
... 41° Navigation Home Giants A's Sharks Warriors Kings 49ers Raiders Quakes Insiders More Tickets Shop Watch Staley: 'A lot of different variables...been ...

Expert Reveals the Latest Variable Capacity Technology
Learn about gForce Ultra CRAC equipment, the latest variable capacity technology to lower energy usage and increase reliability.

Resources last updated: 1/14/2016 7:31:24 AM