Write your first program.
The first program in the 1978 book "The C Programming Language" was to print "hello world!" on the screen. Since then it is used as the first program to introduce the basics of a programming language.
Watch this video to learn about the new concepts shown in the program:
The new commands used in this program and others that may be useful. Select them below to learn more:
//The double forward slash symbols are used to start a comment. Comments are used to explain the purpose of parts of the program. You can write a multi-line comment by using /* */. E.g.
/*
This is a
multi-line comment
*/
static void subprogram(parameters)Defines a new subprogram. Subprograms are also called subroutines. They are used to deconstruct a program into smaller parts to make it easier to read and solve. The body of the subprogram goes between curly braces { }. You cannot use spaces in the name of a subprogram, so use underscores to separate words instead.
static means the subprogram belongs to the program. void means the subprogram does not return a value, and can be replaced with any data type when the subprogram does return a value.
Console.WriteLine(x);Outputs x to the screen. Each Console.WriteLine statement puts the output on a new line. You can prevent a new line by using Console.Write instead. E.g.
Console.Write("Hello");
Console.Write("World");
Console.WriteLine();
Outputs a blank line or ends the line if a new line was prevented.
Questions to think about with this program to check your understanding:
Identify a string in the program.
The words "Hello World" is a string.
State what strings must always be enclosed in.
Strings must be enclosed in double quotation marks (also known as quotes, quote marks, speech marks, inverted commas, or talking marks). These are known as “qualifiers”.
Change the program below so that it:
Hello World
This is my first C# program.
// Hello World program
using System;
class Submission
{
---
// -------------------------
// Subprograms
// -------------------------
---
static void output()
{
---
Console.WriteLine("Hello World");
---
Console.WriteLine("This is my first C# program.");
---
}
---
// -------------------------
// Main program
// -------------------------
public static void Main(string[] args)
{
---
output();
---
}
---
}