Increment return value of method every time it is called
This is a topic on Increment return value of method every time it is called within the Programmers Corner forums, part of the Technology category; Hi,
I want to use a function in the code file of ASP.NET such that everytime the function is called, ...
-
Uber Newbie
Increment return value of method every time it is called
Hi,
I want to use a function in the code file of ASP.NET such that everytime the function is called, its value increases by 1.
I thought of a way but it didn't fully work out. I created a class for this and used a static variable in that but the lifetime of static variable in asp.net is till the time the app does not close.
Code:
public class Class1
{
public Class1()
{
//
// TODO: Add constructor logic here
//
}
private static Int32 i =0 ;
public Int32 return_number()
{
i++;
return i;
}
}
Hence, the static variable keeps on storing these values until the app is restarted i.e
Q. 1
Q. 2
Q. 3
For the second time
Q. 4
Q. 5
Q. 6
but I want the serial number to increment from 1,2, 3 every time application starts as it should be. Any work around?
-
Uber Newbie
Re: Increment return value of method every time it is called

Originally Posted by
optimus_prime
Hi,
but I want the serial number to increment from 1,2, 3 every time application starts as it should be. Any work around?
i don know asp but the logic remains the same, here you go..
the variable is lost as soon as the application is closed so
use a file to store the value and next time read value form the file. I think this should solve your problem.
-
Uber Newbie
Re: Increment return value of method every time it is called
i was thinking same as Dronzer ..
-
Uber Newbie
Re: Increment return value of method every time it is called

Originally Posted by
aadisriram
i was thinking same as Dronzer ..
Thats the Only way of thinking for this problem.. Unless the data is stored it cant be retained..
-
Uber Newbie
Re: Increment return value of method every time it is called
im not asp.net coder but php coder but can give you idea.
you may store it to a file or in sql db ( if its just one variable then dont recommend sql db).
-
Tech2 Members
Re: Increment return value of method every time it is called
Store it in a file, retrive it on run
-
Uber Newbie
Re: Increment return value of method every time it is called
I think bumping of old topics is not allowed.
anyways, seems like you bumped a topics of my first day on chip. :mrgreen:
-
Tech2 Members
Re: Increment return value of method every time it is called
Had no work, just was answering a few unsolved posts, made a mistake at this one
Similar Threads
-
By htnakirs in forum PC Hardware
Replies: 6
Last Post: 12-11-2006, 08:34 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules