Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » C# Variable Passing Question
Closed Thread
Old 02-18-2008, 04:28 AM   #1 (permalink)
Baez's Avatar
 

Join Date: Sep 2005

Location: Toronto, Canada

Posts: 5,479

Baez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of light

Question C# Variable Passing Question

Hey guys starting to learn a little C# now that I'm a C/C++ guru!

I'm writing some code that will increment/decrement a labels value depending on the radio button clicked in a list. The problem I'm having is that I don't want it to increment if I click on a radio with a value of 30 when going from a radio with a value of 40 the first time. It should go down by 10. But of course it doesn't save any variables with postback.

This is my code so far: test.txt

So if you could give any suggestions on how to save the last value in my "Prev" function that would be great.
__________________

Baez is offline  
Old 02-18-2008, 07:30 AM   #2 (permalink)
 
Software Developer

Join Date: Mar 2006

Location: Columbus, OH

Posts: 569

jaeusm is on a distinguished road

Default Re: C# Variable Passing Question

You should be using a private field to store your value rather than relying on a method call (which is what a property really is) to convert a string to an int every time you access the value. In your case, you may want two fields -- _value and _oldValue. In your increment/decrement methods, check to see if you should increment/decrement by one or 10.
jaeusm is offline  
Old 02-19-2008, 11:03 AM   #3 (permalink)
Baez's Avatar
 

Join Date: Sep 2005

Location: Toronto, Canada

Posts: 5,479

Baez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of light

Default Re: C# Variable Passing Question

Okay so I should use a private field. But on the next page load wouldn't the value just be erased?
__________________

Baez is offline  
Old 02-19-2008, 12:10 PM   #4 (permalink)
 
Software Developer

Join Date: Mar 2006

Location: Columbus, OH

Posts: 569

jaeusm is on a distinguished road

Default Re: C# Variable Passing Question

I am a C# developer by profession, but I am not an ASP developer. Unless a new object is created before each Page_Load method is executed, the value of a class variable will remain unchanged. The easiest way to find out is to try it and see what happens.
jaeusm is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
(Java) Problem creating and passing an Integer object? Toshiro Programming Discussions 1 10-17-2007 08:00 PM
Power Supply Question + Overclocking Question Grievearz Building, Buying, or Upgrading High Performance PC Systems 21 09-12-2007 12:59 AM
Folder Variable steak1986 Windows Operating Systems and Software 0 08-23-2007 12:12 PM
Unique Question needs a unique Answer ! MrWiggle Virus - Spyware Protection / Detection 12 07-24-2007 02:45 PM
Question about Video Cards and Compiz Fusion aetherh4cker Linux, BSD, other *nixes & Open Source Software 4 07-19-2007 04:16 PM