Chapter 2 Updated
Chapter 2 Updated
C# Programming Language
• The elements that facilitate the storage of characters and numbers in the
random-access memory.
• A combination of alphabetic characters, numeric digits, and the underscore could be used.
• The first character in the name may not be a numeric.
• No spaces can be placed between characters.
• Reserved words like keywords cannot be use.
• The at sign (@) could be use as the first character.
• Case sensitive
• Use meaningful names that represent the item being described.
VARIABLES – NAMING CONVENTION
A red underline shows that there’s an error in the specific code. This shows that the fullname is
not been declared.
VARIABLES - DECLARATION
A green underline shows that the specific variable is not used in the entire
Program.
VARIABLES - DECLARATION
• Run-time initialization - the user has to enter the value and that value is
copied to the required variable.
C# DATATYPES
DATATYPES
Value Data type- Holds a data value within its own memory space. It means
variables of these data types directly contain their values.
DATATYPES – VALUE DATATYPES
SIGNED UNSIGNED
Indicates that a variable can hold negative and Indicates a variable that can hold only positive
positive values. numbers.
DATATYPES – VALUE DATATYPES
Reference Data type- Do not contain the actual data stored in a variable, but it
contains a pointer to another memory location that holds the data.
DATATYPES – REFERENCE DATATYPES
Implicitly declared variables could store different kind of datatype depending on the first value
it received.
DATATYPE CONVERSION
IMPLICIT CONVERSION
EXPLICIT CONVERSION
• Int.parse()
• Convert.ToInt32()
• (int)variable
OUTPUT FORMATTING
STRING OUTPUT FORMATTING
• Refer to fixed values that the program may not alter during its execution.
These fixed values are also called literals.
• Itcan be of any of the basic data types like an integer constant, a floating
constant, a character constant, or a string literal.
• Itis treated just like regular variables except that their values cannot be
modified after their definition.
CONSTANTS
• Constants are declared using the const keyword, while literals are
values used directly in code without any special keyword.
• Constants must be assigned a value at the time of declaration and
cannot be changed afterward. Literals are used directly as values.
• Constants are typically used for values that should remain fixed
throughout the program, while literals are used for temporary, directly
specified values.
OPERATORS AND ITS
PRECEDENCE
OPERATORS
The assignment operator (=) assigns its right-hand value to its left-hand
variable, property, or indexer. It can also be used with other arithmetic, Boolean
logical, and bitwise operators.
OPERATORS - ARITHMETIC OPERATORS
The arithmetic operators perform arithmetic operations on all the numeric type
operands such as sbyte, byte, short, ushort, int, uint, long, ulong, float, double,
and decimal.
OPERATORS - ARITHMETIC OPERATORS
OPERATORS – COMPOUND ASSIGNMENT OPERATORS
A compound assignment operator has a shorter syntax to assign the result. The
operation is performed on the two operands before the result is assigned to the
first operand.
OPERATORS – COMPOUND ASSIGNMENT OPERATORS
OPERATORS – COMPARISON/RELATIONAL OPERATORS
Comparison operators compare two numeric operands and returns true or false.
It is used in conditional statements, especially in loops, where the result of the
comparison decides whether execution should proceed.
OPERATORS – COMPARISON/RELATIONAL OPERATORS
OPERATORS – COMPARISON/RELATIONAL OPERATORS
OPERATORS – EQUALITY OPERATORS
The equality operator checks whether the two operands are equal or not.
OPERATORS – EQUALITY OPERATORS
Example:
OPERATORS - BOOLEAN LOGICAL
OPERATORS
Example:
bool x = 2+3 > 1*4 && 5/5 == 1;
OPERATORS – OPERATOR PRECEDENCE