To add two numbers in C#, we can use the "+" operator. Here's an example:
main.cs122 chars6 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.cs26 chars2 lines
gistlibby LogSnag