Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Basic C#

Language

JAMES BRIAN FLORES


Instructor
Understanding Statements

A statement is a command that performs an action. You


combine statements to create a method. Statements in C#
follow a well-defined set of rules describing their format
and construction. These rules are collectively known as
syntax.
One of the simplest and most important C# syntax rules
states that you must terminate all statements with a semi-
colon(;).
Using Identifiers
Identifying Keywords
Keywords are reserved words predefined to the C# compiler.
These keywords cannot be used as identifiers.
Output Statement

Console.Write()
- puts text on the console window. The Write() method
outputs one or more values to the screen without a new
line character.

Example:

Console.Write(“Hello World”);
Output Statement
Console.WriteLine()
- renders a line of text on the console. It is a useful
Console method. In its simplest form it outputs the string
argument with a trailing newline.
The WriteLine() always appends a new line character to
the end of the string. this means any subsequent output
will start on a new line.

Example:
Console.WriteLine(“Hello World”);

Note: You can apply escape sequence \n (for new line) and \t (for tabbing).
Workshop:

1. Create an output statement that will display


your I.D. Number, Name and Course in the
console window using Write( ) method.

2. Create an output statement that will display


your Address, Birthday, and Age in the console
window using WriteLine( ) method.
Input Statement

Console.Read( )
is used to read just a single character.

The Read( ) method blocks its return while you type


input characters; it terminates when you press the Enter
key. Subsequent calls to the Read( ) method retrieve your
input one character at a time.

Example: Console.Write(“Enter a letter: ”);


Console.Read();
Input Statement

Console.ReadLine( )
reads input from the console.

ReadLine( ) method is used to read a line of characters


from the standard input stream. When the user presses
Enter, it returns a string.

Example: Console.Write(“Enter your name: ”);


Console.ReadLine();
Comments in C#

Comments
- are used for explaining code. Compilers ignore the
comment entries. Comments are a very useful way to
remind yourself what the programme does, or what a
particular part of your code is for.

Symbols:
// - single line comments.
/* */ - multiline comments.
Sample Program:

You might also like