i am new in c#. I have a windows form program that can show odd number from 1 to n. This is the source code :
List<int> t = Enumerable.Range(1, 123456).ToList();
var oddNumbers = t.Where(num => num % 2 != 0);
txtHasil.Text += oddNumbers.Sum() + Environment.NewLine;
txtHasil.Text += string.Join(",", oddNumbers.Select(n => n.ToString()).ToArray()) + Environment.NewLine;
txtHasil.Text += oddNumbers.Count() + Environment.NewLine;
If i use 1234 in the range, the program work well. If i use 12345 in the range, the program still work well. But if i use 123456 in the range, the program error "Arithmetic operation resulted in an overflow" in oddNumbers.Sum() line.
What should i do for 123456 data ?