Can't understand the result of one simple code

Jan 31 2014 2:05 AM
Dear Members,
 
I am a fresh beginner in programming just started few days ago, I am totally new!
 
While studying one of the examples about the integers (byte and int) I can't understand why it gives this result:
 
here is the code:
 ----------------------------------
  1. // Use byte.
  2. using System;
  3. class Use_byte {
  4. static void Main() {
  5. byte x;
  6. int sum;
  7. sum = 0;
  8. for(x = 1; x <= 100; x++)
  9. sum = sum + x;
  10. Console.WriteLine("Summation of 100 is " + sum);
  11. }
  12. }
------------------------- 
the result is:
 
 Summition of 100 is 5050
 
----------------- 
 
Can anyone please  explainstep by step why it shows 5050 and what is the logic of this code..
 
Thanks a lot. 

Answers (8)