Skip to main content

Basic Things

Structure

Before going into C# programming, we should look at the minimum structure C# programm.

using System;
namespace Program {
class Program {
static void Main (string[] args) {
Console.WriteLine("Hello World!");
Console.ReadLine();
}
}
}

When this code is compiled and executed, it will display Hello World"!.

note
  • C# is case sensitive !
  • All the statement/declaration must end with a semicolon (;).
  • The program execution starts at the Main method.

Input and Outputs

The command to input is Console.WriteLine();.

However, the command to output or display is Console.ReadLine();.

Arithmetic Operator

Arithmetic operator are simple mathematic operation. The following table shows all the arithmetic operator -

OperatorDescriptionExample
+Adds two operandA + B = 30
-Substract second operand from the listA - B = 10
*Mutiples both operandsA * B = 200
/Divides numerator by de-numeratorB/A = 2
% Modulus Operator and remainder of after an integer divisionB/A=2
++Increment oprator increases integer value by oneA ++= 11
--Decrement operator decreases integer value by oneA --= 9

Relational Operators

Relational operator are operator that defines a replation between two entities.

OperatorDescriptionExample
==Checks if the values of two operands are equal or not, if yes then condition becomes true.(A == B) is not true
!=Checks if the values of two operands are equal or not, if values are not equal then condition becomes true.(A!=B) is true.
>Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true.(A>B) is not true
<Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true.(A < B) is true.
>=Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true.(A >= B) is not true.
<=Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true.(A <= B) is true.

Logical Operator

Logical operator are operator that connect two or more expression.

OperatorDescriptionExample
&&Called Logical AND operator. If both the operands are non zero then condition becomes true.(A && B) is false.
!Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.!(A && B) is true.

Assign Operator

The assignment Operator is the operator used to assign a new value to a variable.

OperatorDescriptionExample
=Simple assignment operator, assigns value from right side operands to left side operandX = A
+=Add AND assignment operator, it adds right operand to the left operand and assign the result to left operandX += A is the same as X = A + X
-=Substract AND assignment operator, it subtracts right operand from the left operand and assign the result to the left operandX -= A
*=Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operandC *= A
/=Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operandC /= A
%=Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operandC %= A

Concatenation

Concatenation is the process of appending one string to the end of another string. You concatenate strings by using the + operator.

using System;

namespace Program {

class Program {

static void Main(string[] args) {
Console.WriteLine("Hello World!" + "Welcome to...");
Console.ReadLine();
}
}
}

Key Words

  • Relational Operator

  • Logical Operator

  • Operand - is a value

  • Assign

  • Variable - is a "storage" that contains the information

  • Datatype - allocates a specific memory

  • Concatenation

  • Expression - is a mathematical logic that return a value. For example, A + B = X

  • Decision

  • Statements

  • Algorihm - is a set of instruction

  • Maths Function -

    • Ceiling

    • Floor

    • Math.Abs, etc..

  • Control Structure - is used to specify the flow of the program: iteraion, sequence and

  • Iteration - are loops: while loop, do while loop, for loop and for each loop. It needs to have a control variable.

  • Control Variable -

  • Block Statements - is a where instruction are inside the statements, usually condition

  • Branch Statements

  • Sequence

  • Syntax - is the language rule

  • Concatenation

  • Function - is a block of code that performs a specific task

    it will return a value

  • Procedure - is a block of code that performs a specific task that does not return a value.

  • Method - combines fuction and procedure together

  • Library - is a collection of prewritten code that performs specific

  • Access Specifier

  • Arguments

  • Parameters

  • Subroutine

  • Arrays:

    • FindAll
    • Findwith
    • ArrayLenght
  • Static