0% found this document useful (0 votes)
10 views

C Sharp

C# is a high-level programming language used to create applications for Microsoft Windows operating systems. A C# program consists of namespaces, classes, methods, attributes, and a Main method. Variables are used to store and retrieve information and can change their value. Variables are declared with a data type, identifier, and optional initialization. C# supports common data types like integers, floats, booleans, characters and strings. Type conversion allows converting between data types. C# provides arithmetic, assignment, comparison, and logical operators to perform operations.

Uploaded by

KD Andres
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

C Sharp

C# is a high-level programming language used to create applications for Microsoft Windows operating systems. A C# program consists of namespaces, classes, methods, attributes, and a Main method. Variables are used to store and retrieve information and can change their value. Variables are declared with a data type, identifier, and optional initialization. C# supports common data types like integers, floats, booleans, characters and strings. Type conversion allows converting between data types. C# provides arithmetic, assignment, comparison, and logical operators to perform operations.

Uploaded by

KD Andres
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

C# (C Sharp)

What is C#?
• It is a language for professional programming.
• It is a high-level programming language.
• It is used in creating applications that run on Microsoft
Windows operating systems.
A C# program consists of the following parts:
• Namespace declaration
• A class
• Class methods
• Class attributes
• A Main method
• Statements and Expressions
• Comments
Variable
A variable is a container of information, which can change its
value. It provides means for:
1. Storing information;
2. Retrieving the stored information;
3. Modifying the stored information.
Variable Declaration

<data type> <identifier> [=<initialization>];

Example:
string User_Name = "Bernard Jacobe";
int age = "25";
string gender;
Reserved Words
They cannot be used as
programmer's identifiers
or variable names.
Data Types
This is a set of data that specifies the possible range of values of the set, the
operations that can be performed on the values, and the way in which the values are
store in memory.
Data Type Size Description
int 4 bytes Stores whole numbers from -2,147,483,648 to 2,147,483,647
long 8 bytes Stores whole numbers from -9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
float 4 bytes Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits
double 8 bytes Stores fractional numbers. Sufficient for storing 15 decimal digits
bool 1 bit Stores true or false values
char 2 bytes Stores a single character/letter, surrounded by single quotes
string 2 bytes per Stores a sequence of characters, surrounded by double quotes
character
Type Conversion
Type conversion is converting one type of data to another type. It is also known as
Type Casting.
C# Type Conversion Methods
Methods Description
ToBoolean Converts a type to a Boolean value, where possible.
ToByte Converts a type to a byte.
ToChar Converts a type to a single Unicode character, where possible.
ToDateTime Converts a type (integer or string type) to date-time structures.
ToDecimal Converts a floating point or integer type to a decimal type.
ToDouble Converts a type to a double type.
ToInt16 Converts a type to a 16-bit integer.
ToInt32 Converts a type to a 32-bit integer.
ToInt64 Converts a type to a 64-bit integer.
C# Type Conversion Methods
Methods Description
ToSbyte Converts a type to a signed byte type.
ToSingle Converts a type to a small floating point number.
ToString Converts a type to a string.
ToType Converts a type to a specified type.
ToUInt16 Converts a type to an unsigned int type.
ToUInt32 Converts a type to an unsigned long type.
ToUInt64 Converts a type to an unsigned big integer.
C# Operators
An operator is a symbol that tells the compiler to perform specific
mathematical or logical manipulations. C# provides the following type of
operators:

1. Arithmetic Operators
2. Assignment Operators
3. Comparison Operators
4. Logical Operators
Arithmetic Operators
Arithmetic operators are used to perform common mathematical
operations:
Operator Name Description Example
+ Addition Adds together two values x+y
- Subtraction Subtracts one value from another x-y
* Multiplication Multiplies two values x*y
/ Division Divides one value by another x/y
% Modulus Returns the division remainder x%y
++ Increment Increases the value of a variable by 1 x++

-- Decrement Decreases the value of a variable by 1 x--


Assignment Operators
Assignment operators are used to assign values to variables.
Operator Example Same As
= x=5 x=5
+= x += 3 x=x+3
-= x -= 3 x=x-3
*= x *= 3 x=x*3
/= x /= 3 x=x/3
%= x %= 3 x=x%3
&= x &= 3 x=x&3
|= x |= 3 x=x|3
^= x ^= 3 x=x^3
>>= x >>= 3 x = x >> 3
<<= x <<= 3 x = x << 3
Comparison Operators
Comparison operators are used to compare two values:

Operator Name Example

== Equal to x == y

!= Not equal x != y

> Greater than x>y

< Less than x<y

>= Greater than or equal to x >= y

<= Less than or equal to x <= y


Logical Operators
Logical operators are used to determine the logic between variables or
values:

Operator Name Description Example

&& Logical and Returns true if both statements are x < 5 && x < 10
true

|| Logical or Returns true if one of the x < 5 || x < 4


statements is true

! Logical not Reverse the result, returns false if !(x < 5 && x < 10)
the result is true

You might also like