Talow
Sorceror
First what is an operator?
Well an operators are symbols that specify which operations to perform in an expression.
For more on operators in C# visit: http://msdn.microsoft.com/en-us/library/6a71f45d.aspx
So a + or a - or even a = are operators, so which operator is this tutorial for?
The modulus(mod) operator, whose symbol is %. I'm sure you know that being percent, but in our environment it means modulus.
So here is where I tell you what it do to save you a google trip. When you divide 2 values the modulus is the remainder. So if you where to do 5/2 you would get 2, but where did that extra one go? well it's not part of this division, but if you do the same thing with a %, or 5%2 you get 1, and that's the remainder.
So what are some uses for this guy?
They can help out with looping in large scales, though division.
lets say you have a list, you don't know how long the list could be, but you know that there are 6 options for this list, and that's it...
so we can assign the list count and mod it by 6, so now, no mater what our answer is going to come out with a reference of 0-5.
60%6 = 0 there is no remainder
61%6 = 1
62%6 = 2
...
65%6 = 5
66%6 = 0
and this is how it will continue. So now you can figure out which option of that list was referenced without having to drop a for loop and search it out, so you can then us this in a switch...
So now you can see that no matter how long the list, it will return into your case, because your case has the 6 options and by finding the remainder of the count divided by 6 you can only get 6 answers (yes we count 0).
FYI: 0 % x where x = any integer = 0
Well an operators are symbols that specify which operations to perform in an expression.
For more on operators in C# visit: http://msdn.microsoft.com/en-us/library/6a71f45d.aspx
So a + or a - or even a = are operators, so which operator is this tutorial for?
The modulus(mod) operator, whose symbol is %. I'm sure you know that being percent, but in our environment it means modulus.
So here is where I tell you what it do to save you a google trip. When you divide 2 values the modulus is the remainder. So if you where to do 5/2 you would get 2, but where did that extra one go? well it's not part of this division, but if you do the same thing with a %, or 5%2 you get 1, and that's the remainder.
So what are some uses for this guy?
They can help out with looping in large scales, though division.
lets say you have a list, you don't know how long the list could be, but you know that there are 6 options for this list, and that's it...
so we can assign the list count and mod it by 6, so now, no mater what our answer is going to come out with a reference of 0-5.
60%6 = 0 there is no remainder
61%6 = 1
62%6 = 2
...
65%6 = 5
66%6 = 0
and this is how it will continue. So now you can figure out which option of that list was referenced without having to drop a for loop and search it out, so you can then us this in a switch...
Code:
switch(listref.Count%6)
{
count:0
{
//here the remainder = 0
}
count:1
{
//I'm so not writeing this for each one.
}
count:2
{
//I do think you get the point right?
}
}
FYI: 0 % x where x = any integer = 0