Unit 1: Introduction to C# PRACTICAL UNDERSTANDING Flashcards
SYNTAX AT THE BEGINNING OF THE PROGRAM
using System;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
using System
means that we can use classes from the System namespace.
A blank line.
C# ignores white space. However, multiple lines makes the code more readable.
namespace
is used to organize your code, and it is a container for classes and other namespaces.
The curly braces {}
marks the beginning and the end of a block of code.
class is a
container for data and methods, which brings functionality to your program.
Every line of code that runs in C# must be inside a class. In our example, we named the class Program.
Another thing that always appear in a C# program, is the Main method.
Any code inside its curly brackets {} will be executed.
You don’t have to understand the keywords before and after Main. You will get to know them bit by bit while reading this tutorial.
If you omit the using System line
you would have to write System.Console.WriteLine() to print/output text.
Console is a class of the
System namespace,
Every C# statement ends with a
semicolon ;
“MyClass” and “myclass” has different meaning. BECAUSE
C# is case-sensitive:
Single-line comments start with
two forward slashes//
Multi-line comments start with
/*
Multi-line ends with
*/
To output values or print text in C#, you can use the
WriteLine() method
This will output Hello World….?
Console.WriteLine(“Hello World!”);
Console.WriteLine(9 + 3);
This will output 12
There is also a method, which is similar to WriteLine().
Write()
The only difference is that it does not insert a new line at the end of the output
Write()
IT PRINTS ON THE SAME LINE
stores integers (whole numbers), without decimals, such as 123 or -123
int
stores floating point numbers, with decimals, such as 19.99 or -19.99
double -
stores single characters, such as ‘a’ or ‘B’. Char values are surrounded by single quotes
char
- stores text, such as “Hello World”. String values are surrounded by double quotes
string
- stores values with two states: true or false
bool