sum numbers from 1 to 10 in csharp

main.cs
int sum = 0;
for (int i = 1; i <= 10; i++) {
    sum += i;
}
Console.WriteLine("The sum of numbers from 1 to 10 is {0}", sum);
127 chars
6 lines

In this code block, we declare a variable sum to hold the sum of the numbers. We then use a for loop to iterate over the numbers from 1 to 10, and use the += operator to add each number to the sum variable. Finally, we print out the result using the Console.WriteLine method. This is an example of using control flow statements, arithmetic operators, and variables in C#.

gistlibby LogSnag