For Every Ten Digits
-
How would I, for every 10 numbers in an int, do an event? What I need help with is the foreach part? I'm confused as of what exactly to put: foreach (myInt in ???) { } Thanks.
- I love D-flat!
Every 10 digits in what int ? You mean as in the int 12345678901 fires one event ? When ? When it's being entered ? If you have a string you can use the length property to check how long it is.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Every 10 digits in what int ? You mean as in the int 12345678901 fires one event ? When ? When it's being entered ? If you have a string you can use the length property to check how long it is.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
int But I don't undertand how to calculate this in the language. foreach (myInt in (what goes here?)
- I love D-flat!
-
int But I don't undertand how to calculate this in the language. foreach (myInt in (what goes here?)
- I love D-flat!
-
Convert the number to a string, then loop through the characters in that string.
Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush
int.MaxValue
is 2147483647. (Which is 10 digits). Without using a 'bigger' space to store an integer (Int64) this will only 'fire' once if at all. If this is true and you are using anint
thenif (myInt > 999999999)...
will be sufficient. If the integer is in string form thenmyStr.Length / 10
will give you the number of 'ten digits' there are in the string.Matthew Butler
-
How would I, for every 10 numbers in an int, do an event? What I need help with is the foreach part? I'm confused as of what exactly to put: foreach (myInt in ???) { } Thanks.
- I love D-flat!
MasterSharp, I think you've misunderstood the foreach slightly.
Foreach (int currentInt in myInt)
currentInt is the current int the foreach is at in the iteration. myInt is the collection you want to iterate through. So, if you wanted to fire an event every 10 digits, you could do:int myInt = 100; int tenDigit = 0; foreach (int currentInt in myInt) { if (tenDigit == 10) { tenDigit = 0; If (Event != null) Event(this, new EventArgs()); } tenDigit++; }
Hope this helps. Regards, Gareth. -
MasterSharp, I think you've misunderstood the foreach slightly.
Foreach (int currentInt in myInt)
currentInt is the current int the foreach is at in the iteration. myInt is the collection you want to iterate through. So, if you wanted to fire an event every 10 digits, you could do:int myInt = 100; int tenDigit = 0; foreach (int currentInt in myInt) { if (tenDigit == 10) { tenDigit = 0; If (Event != null) Event(this, new EventArgs()); } tenDigit++; }
Hope this helps. Regards, Gareth.Yes, thank you all.
- I love D-flat!
-
MasterSharp, I think you've misunderstood the foreach slightly.
Foreach (int currentInt in myInt)
currentInt is the current int the foreach is at in the iteration. myInt is the collection you want to iterate through. So, if you wanted to fire an event every 10 digits, you could do:int myInt = 100; int tenDigit = 0; foreach (int currentInt in myInt) { if (tenDigit == 10) { tenDigit = 0; If (Event != null) Event(this, new EventArgs()); } tenDigit++; }
Hope this helps. Regards, Gareth.gareth111 wrote:
int myInt = 100; int tenDigit = 0; foreach (int currentInt in myInt)
myInt
is an integer.Foreach
requires a collection, or some object that has an enumerator defined.Small angry dogs
My 1000th post!!
-
gareth111 wrote:
int myInt = 100; int tenDigit = 0; foreach (int currentInt in myInt)
myInt
is an integer.Foreach
requires a collection, or some object that has an enumerator defined.Small angry dogs
My 1000th post!!
-
MasterSharp, I think you've misunderstood the foreach slightly.
Foreach (int currentInt in myInt)
currentInt is the current int the foreach is at in the iteration. myInt is the collection you want to iterate through. So, if you wanted to fire an event every 10 digits, you could do:int myInt = 100; int tenDigit = 0; foreach (int currentInt in myInt) { if (tenDigit == 10) { tenDigit = 0; If (Event != null) Event(this, new EventArgs()); } tenDigit++; }
Hope this helps. Regards, Gareth.