C# Programming Essential
Tahaluf Training Center 2021
Tahaluf Training Centre 16 May 2021 20210022
Chapter 1
1 Overview of Visual Studio 2019
1
2 Overview of C# language
3 Create Console App (.NET Framework) Project
4 WriteLine or Write
5 Declaring (Creating) Variables and Constants
6 Type Casting
Tahaluf Training Centre 16 May 2021 20210022
Overview of Visual Studio
2019
The Visual Studio integrated development environment is a
creative launching pad that you can use to edit, debug, and build
code, and then publish an app.
Tahaluf Training Centre 16 May 2021 20210022
Overview of Visual Studio
2019
Tahaluf Training Centre 16 May 2021 20210022
Chapter 1
1 Overview of Visual Studio 2019
1
2 Overview of C# language
3 Create Console App (.NET Framework) Project
4 WriteLine or Write
5 Declaring (Creating) Variables and Constants
6 Type Casting
Tahaluf Training Centre 16 May 2021 20210022
Overview of C# Language
C# is an elegant and type-safe object-oriented language that
enables developers to build a variety of secure and robust
applications that run on the .NET Framework.
You can use C# to create Windows client applications, XML Web
services, distributed components, client-server applications,
database applications, and much more.
Tahaluf Training Centre 16 May 2021 20210022
Overview of C# Language
Popularity of Programming Language Worldwide, May 2021 compared
to a year ago:
Tahaluf Training Centre 16 May 2021 20210022
Chapter 1
1 Overview of Visual Studio 2019
1
2 Overview of C# language
3 Create Console App (.NET Framework) Project
4 WriteLine or Write
5 Declaring (Creating) Variables and Constants
6 Type Casting
Tahaluf Training Centre 16 May 2021 20210022
Create Console App (.NET Framework)
Project
Open Visual Studio 2019 => Select Create a new project =>
Select Console App (.NET Framework) (C#, Windows,
Console) => Enter Project Name => Click on create.
Tahaluf Training Centre 16 May 2021 20210022
Create Console App (.NET Framework)
Project
Tahaluf Training Centre 16 May 2021 20210022
Create Console App (.NET Framework) Project
▪ Using System means that we can use classes from the System
namespace.
▪ Namespace is a used to organize your code, and it is a container
for classes and other namespaces.
▪ The curly braces {} marks the beginning and the end of a block of
code.
Tahaluf Training Centre 16 May 2021 20210022
Create Console App (.NET Framework) Project
• Class is a container for data and methods, which brings
functionality to your program.
• Every line of code that runs in C# must be inside a class. In our
example, we named the class Program.
Tahaluf Training Centre 16 May 2021 20210022
Create Console App (.NET Framework) Project
• Another thing that always appear in a C# program, is the
Main method. Any code inside its curly brackets {} will be
executed.
• You don't have to understand the keywords before and after
Main.
Tahaluf Training Centre 16 May 2021 20210022
Create Console App (.NET Framework) Project
• Console is a class of the System namespace, which has a WriteLine()
method that is used to output/print text.
• Every C# statement ends with a semicolon ( ; ).
• C# is case-sensitive: "MyClass" and "myclass" has different meaning.
Tahaluf Training Centre 16 May 2021 20210022
Chapter 1
1 Overview of Visual Studio 2019
1
2 Overview of C# language
3 Create Console App (.NET Framework) Project
4 WriteLine or Write
5 Declaring (Creating) Variables and Constants
6 Type Casting
Tahaluf Training Centre 16 May 2021 20210022
WriteLine or Write
• WriteLine():
• Write() :
Tahaluf Training Centre 16 May 2021 20210022
Exercise
Write a C# Sharp program to print Hello and
your (name, Age ,University, Specialization)
in a separate line.
Tahaluf Training Centre 16 May 2021 20210022
Chapter 1
1 Overview of Visual Studio 2019
1
2 Overview of C# language
3 Create Console App (.NET Framework) Project
4 WriteLine or Write
5 Declaring (Creating) Variables and Constants
6 Type Casting
Tahaluf Training Centre 16 May 2021 20210022
Declaring (Creating) Variables and
Constants
• In C#, there are different types of variables (defined with different
keywords), for example:
1. Int: stores integers (whole numbers), without decimals, such as 123 or -
123.
2. Double: stores floating point numbers, with decimals, such as 19.99 or -
19.99.
3. Char: stores single characters, such as 'a' or 'B'. Char values are
surrounded by single quotes.
4. String: stores text, such as "Hello World". String values are surrounded by
double quotes.
5. Bool: stores values with two states: true or false.
Tahaluf Training Centre 16 May 2021 20210022
Declaring (Creating) Variables and
Constants
• To create a variable, you must specify the type and assign it a
value:
type variableName = value;
Tahaluf Training Centre 16 May 2021 20210022
Declaring (Creating) Variables and Constants
Tahaluf Training Centre 16 May 2021 20210022
Exercise
Print your name and age in a separate line, then
print line of * using comment and print it in the
same line.
Tahaluf Training Centre 16 May 2021 20210022
Exercise
Store your first Name and last name in a variable
then print a full name.
Tahaluf Training Centre 16 May 2021 20210022
Declaring (Creating) Variables and Constants
• constant means unchangeable and read-only.
Tahaluf Training Centre 16 May 2021 20210022
Chapter 1
1 Overview of Visual Studio 2019
1
2 Overview of C# language
3 Create Console App (.NET Framework) Project
4 WriteLine or Write
5 Declaring (Creating) Variables and Constants
6 Type Casting
Tahaluf Training Centre 16 May 2021 20210022
Type Casting
In C#, there are two types of casting:
• Implicit Casting (automatically): converting a smaller type to a
larger type size char -> int -> long -> float -> double.
Tahaluf Training Centre 16 May 2021 20210022
Type Casting
• Explicit Casting (manually): converting a larger type to a smaller
size type double -> float -> long -> int -> char.
Tahaluf Training Centre 16 May 2021 20210022
Exercise
Print ASCII value for A character using
implicit casting.
Tahaluf Training Centre 16 May 2021 20210022
Type Casting
Type Conversion Methods:
Tahaluf Training Centre 16 May 2021 20210022
Type Casting
Tahaluf Training Centre 16 May 2021 20210022
Exercise
Write a code to print your name in separate characters,
ASCII value for each character, your name using
concatenation and the sum of the ASCII values.
Tahaluf Training Centre 16 May 2021 20210022