Professional Documents
Culture Documents
Using Statements;
using System; - This imports the entire ‘System’ namespace, which contains
fundamental types and base classes that define commonly-used value and reference
data types, events and event handlers, interfaces, attributes, and processing
exceptions.
using System.Collections.Generic; - This imports the ‘System.Collections.Generic’
namespace, which contains interfaces and classes that define generic collections,
which allow for type-safe data structures without boxing and unboxing to and from
objects.
using System.Linq; - This imports the ‘System.Linq’ namespace, which provides
classes and interfaces that support queries that use Language-Integrated Query
(LINQ). LINQ enables you to query collections in a more expressive and concise
manner.
using System.Text; - This imports the ‘System.Text’ namespace, which contains
classes representing ASCII, UTF-8, UTF-16, and UTF-32 characters encodings,
along with classes for converting blocks of characters to and from blocks of bytes.
using System.Threading.Tasks;: This imports the ‘System.Threading.Tasks’
namespace, which provides types that simplify the work of writing concurrent and
asynchronous code. It includes the Task and Task<TResult> classes, which
represent asynchronous operations.
Method Calls:
Console.Writeline(); - Method used to display a text on the console command line
interface.
Console.Write(); - This method writes the specified string or object to the console
without appending a newline character.
Console.Readline(); - used to read a line of text input from the console or command
line interface. It allows the program to wait for the user to input text and then
captures that text for further processing.
Comments:
are used for noting how your code functions/works (the compiler won’t read
comments).
// - Single line comment.
Data Types:
After we put a data type, the next is the variable name which will be the container.
String – Stores texts (many characters) and must always be inside a double
quotation.
int - is a keyword used to declare a variable that can hold integer values.
Keywords:
Out - is a keyword used in method parameters to indicate that the corresponding
argument is an output parameter. When you use out in a method parameter
declaration, you're telling the compiler that the method will assign a value to that
parameter, and that value will be accessible to the caller after the method completes
execution.
, - serves multiple purposes depending on the context in which it is used. Here are
some common uses.
+ - When used with string operands, the + operator concatenates (joins together) the
strings.
break - is used within control flow statements, such as switch, for, while, and do-
while loops, to exit the current loop or switch block prematurely. Its usage varies
depending on the context.
Index - allows you to access elements in a collection using a simplified syntax. It's
particularly useful when working with data structures like arrays, lists, or custom
collections. Indexes always starts at 0.
return - used to exit a method and optionally return a value to the caller. When a
return statement is encountered within a method, the execution of the method is
immediately terminated, and control is returned to the calling code.
in - used as a modifier for parameters in method signatures. It indicates that an
argument is passed by reference, but it's considered read-only within the method.
Conversion:
.ToString(); - is a method that belongs to all objects. It converts the value of the
current object to its string representation.
Arithmetic Operators:
+ - Adds two operands.
- - Subtracts the second operand from the first operand.
* - Multiplies two operands.
/ - Divides first operand by the second operand.
% - Computes the remainder of the division of the first and second operand.
++ - Increments the value of operand by 1.
— - Decrements the value of operand by 1
Relational Operators:
== - Returns true if the two operands are equal, otherwise returns false.
!= - Returns true if the two operands are not equal, otherwise returns false.
> - Returns true if the left operand is greater than the right operand, otherwise
returns false.
< - Returns true if the left operand is less than the right operand, otherwise returns
false.
>= - Returns true if the left operand is greater than or equal to the right operand,
otherwise returns false.
<= - Returns true if the left operand is less than or equal to the right operand,
otherwise returns false.
Logical Operators:
&& - Returns true if both operands are true, otherwise returns false.
|| - Returns true if at least one of the operands is true, otherwise returns false.
! - Returns true if the operand is false, and false if the operand is true.
Switch Statement - is a
control flow statement used to
select one of many code
blocks to be executed based
on the value of an expression.
It's an alternative to using
multiple if...else if...else
statements when you have
multiple conditions to check.
Array - a fixed-size collection of elements of the same type. It provides a convenient
way to store and access multiple values of the same data type sequentially. Arrays
are zero-indexed, meaning the index of the first element is 0, the second element is
1, and so on.
Loops:
for loop - used for iterating over a range of values or elements. It allows you to
execute a block of code repeatedly until a specified condition is met.
Method:
Methods are used to make our line of codes shorter.
Main Method - is the entry point of a C# console application. When you run a C#
console application, the runtime system looks for the Main method as the starting
point for the program's execution. The Main method must be declared as static, and
it serves as the program's starting point from which other methods can be invoked.
Method - a code block that contains a series of statements to perform a specific task
or operation. Methods are fundamental building blocks of C# programs, and they
help organize code into reusable units, improve code readability, and facilitate code
maintenance.