- 5

Can someone explain to me how come the output of the code below is 4?

string s = "SoloLearn"; int x = s.Length; int y = s.IndexOf("e"); Console.Write(x%y);

16th Nov 2016, 7:03 PM
Melo Modiga
Melo Modiga - avatar
5 odpowiedzi
+ 4
9 mod 5 So, The ans will be 4
24th Apr 2021, 7:03 AM
Md. Rakibul Islam
Md. Rakibul Islam - avatar
+ 2
"SoloLearn" is long 9 C# starts to count from 0 , so "S" is in "0" position the "e" is in fifth position 9 mod 5 = 4 and if you don't know what "modulo operation" is : https://en.wikipedia.org/wiki/Modulo_operation
16th Nov 2016, 7:22 PM
LuciferSam
LuciferSam - avatar
0
i think, here important thing is, for .Length method starts with 1 , but index of array starts with 0.
17th Nov 2016, 7:08 PM
Ozan Karataş
Ozan Karataş - avatar
0
im still alil confused can you please explain it over alil slower and whats the meaning of MOD @Sam
13th Oct 2017, 1:05 PM
Allistair
- 1
Here: x = 9 y = 5 ( cause "e" is the 5th index from 0, aka "S" So when x%y is actually saying "what is the remainder from 9 devided by 5, which is 4 because 9/4 is 1 with a remainder of 4, aka 1.4. I hope that helped.
17th Nov 2016, 8:18 PM
Cass