if I declared
Code:
protected void Button1_Click(object sender, EventArgs e) { count++;
protected void Button1_Click(object sender, EventArgs e) { int count=0; count++; int noofcount=count; }
protected void Button1_Click(object sender, EventArgs e) { static int count=0; count++; int noofcount=count; }
static int count = 0; // the count variable's scope is for the class (the page) // it can be used through out the class's (page's) code // it is shared between all instances of this class // static variables must be declared outside of any functions // since they have a class scope // they are shared between all instances of the class protected void Button1_Click(object sender, EventArgs e) { //if the variable had been declared here it would have a scope //for the Button1 Click function only. count++; }
Shared count As Integer ' the count variable's scope is for the class (the page) ' it can be used through out the class's (page's) code ' it is shared between all instances of this class. ' shared variables must be declared outside of any functions ' since they have a class scope ' they are shared between all instances of the class Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click 'if the variable had been declared here it would have a scope 'for the Button1 Click function only. count+=1 End Sub
static int count = 0; protected void Button1_Click(object sender, EventArgs e) { //if the variable had been declared here it would have a scope //for the Button1 Click function only. count++; int noofcount=count; }
var count = 0; function inc_num(){ count++; // do something } <button type="button" onclick="inc_num()" value="Increment" />
Comment