![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Feb 2008
Posts: 32
Rep Power: 0
![]() |
declare Timer.Interval from Options
I want to declare Timer.Interval from Options menu but got one problem = Cannot implicitly convert type 'string' to 'int'
Thanks.
__________________
C# |
|
|
|
|
|
#2 |
|
SEXY SHOELESS GOD OF WAR!
![]() Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,197
Rep Power: 5
![]() |
Re: declare Timer.Interval from Options
I'm not sure what you're trying to ask, here. If it's simply that you have a string like "500", and you want to set an interval of 500, then you can parse the string into an integer. I like using the
TryParse() method, because it returns a boolean (true/false) value indicating success, and if it's successful, it will 'fill in' the variable you give it. Here's a quick example:string intervalString = "500";
int intervalInt;
if( int.TryParse(intervalString, out intervalInt) )
MessageBox.Show("Value: " + intervalInt.ToString(), "Success");
else
MessageBox.Show("String did not contain a text representation of an integer", "Error");TryParse() a string, and a reference to the value to be filled in. The out keyword is necessary here; this tells the compiler that you're passing a reference to a value, and that the method you're calling will fill in the value using this reference. It's similar to the ref keyword, except with ref, you have to have the value initialized before the call (note we don't initialize it before calling TryParse()).Another thing you should know is that all the fundamental types have a TryParse() method. You can use int.TryParse(), double.TryParse(), and so on. They all work in the same manner, with the only difference being the data type. Likewise, there is a Parse() method for built-in types, but I don't much like it, as it throws an exception if the string cannot be converted. I'd rather receive a simple success/failure indication, and handle things that way.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
|
#3 |
|
Unknown
Join Date: Apr 2008
Location: unknown
Posts: 87
Rep Power: 1
![]() |
Re: declare Timer.Interval from Options
lectricpharaoh is so detailed when he explains his answers in his posts.... very well understood
__________________
------------------------------------------------------------------------- I thought what I'd Do was, I'd pretend to be one of those deaf mutes ------------------------------------------------------------------------ |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Install options for published applications | Jabo | Visual Basic .NET | 0 | May 13th, 2008 2:47 PM |
| java options asynchronous garbage collection | secrecy230 | Java | 1 | Mar 17th, 2008 2:54 PM |
| howto declare function in perl | baldy1324 | Perl | 2 | Nov 6th, 2006 10:22 AM |
| Defining and handling command-line options | Jessehk | Python | 6 | Mar 3rd, 2006 11:30 PM |
| Declare array of chars | some1 | C++ | 1 | Apr 28th, 2005 3:14 PM |