add two numbers in csharp

To add two numbers in C#, we can use the "+" operator. Here's an example:

main.cs
int num1 = 5;
int num2 = 10;
int sum = num1 + num2;

Console.WriteLine("The sum of {0} and {1} is {2}", num1, num2, sum);
122 chars
6 lines

In this example, we first declare two integer variables, num1 and num2, and assign them the values 5 and 10, respectively. We then create a third variable called sum, and assign it the result of adding num1 and num2 together.

Lastly, we use the Console.WriteLine() method to output a message that indicates the sum of the two numbers.

The output would be:

main.cs
The sum of 5 and 10 is 15
26 chars
2 lines

gistlibby LogSnag