C# Workshop – Operators



C# supports many kinds of Operators which are symbols that specify which Operations such as mathematics. We’ll cover some of the basic ones here such as addition and multiplication.
The first thing is to define the basic structure of a programme by entering the following in dotnetfiddle.net in the main window:

using System;

public class Demo
	public static void Main()
		// Code

// Code is a Comment which is defined by writing // before anything that can be included in the programme but won’t be run as part of it such as reminders or explanations of what the code should do.
The first Operator to use is + which is used for addition so enter the following below // Code in dotnetfiddle.net:

Console.WriteLine(4 + 2);

Then select Run in dotnetfiddle.net and this will display the answer as the output, it is also possible to use other mathematical Operators so can change + to * for multiply, for subtraction or / for division to see what happens such as entering the following in dotnetfiddle.net:

Console.WriteLine(4 * 2);
Console.WriteLine(4 - 2);
Console.WriteLine(4 / 2);

You should see the appropriate answers appear in the output for each Operator that has been used whether it is addition, multiplication, subtraction or division.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s