SlideShare a Scribd company logo
INTRODUCTION
TO
C# PROGRAMMING
WHY USE C#?
C# is pronounced "C-Sharp".
It is an object-oriented programming language
created by Microsoft that runs on the .NET
Framework.
C# has roots from the C family, and the language is
close to other popular languages like C++ and Java.
The first version was released in year 2002. The
latest version, C# 11, was released in November
2022.
WHY USE C#?
C# is used for:
• Mobile applications
• Desktop applications
• Web applications
• Web services
• Web sites
• Games
• VR
• Database applications
• And much, much more!
WHY USE C#?
• It is one of the most popular programming
language in the world
• It is easy to learn and simple to use
• It has a huge community support
• C# is an object oriented language which gives a
clear structure to programs and allows code to
be reused, lowering development costs
• As C# is close to C, C++ and Java, it makes it
easy for programmers to switch to C# or vice
versa
C# IDE
• The easiest way to get started with C#, is to
use an IDE.
• An IDE (Integrated Development Environment)
is used to edit and compile code.
• Applications written in C# use the .NET
Framework, so we will use Visual Studio, as the
program, the framework, and the language, are
all created by Microsoft.
C# SYNTAX
Example:
C# SYNTAX
Line 1: Using System means that we can use classes
from the System namespace.
Line 2: A blank line. C# ignores white space. However,
multiple lines makes the code more readable.
Line 3: namespace is used to organize your code, and it
is a container for classes and other namespaces.
Line 4: the curly braces { } marks the beginning and the
end of a block of code.
Line 5: 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
the class Program.
C# SYNTAX
Line 7: 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. You will
get to know them bit by bit.
Line 9: Console is a class of the System namespace,
which has a WriteLine() method that is used to
output/print text. In our example it will output “Hello
World!”.
If you omit the using System line, you would have to
write System.Console.WriteLine() to print/output text.
C# SYNTAX
Note: Every C# statement ends with a
semicolon ;
Note: C# is case-sensitive: “MyClass” and
“myclass” has different meaning or use
Note: Unlike Java, the name of the C# file does
not have to match the class name, but they often
do (for better organization). When saving the file,
save it using a proper name and add “.cs” to the
end of the filename.
C# SYNTAX
Don’t worry if you don’t understand
how using System, namespace and
class works. Just think of it as
something that (almost) always
appears in your program, and that you
will learn more about them in a later
chapter.
C# OUTPUT
To output values or print text in C#, you can use
the WriteLine() method:
To can add as many WriteLine() methods as you
want. Note that it will add a new line for each
method:
C# OUTPUT
You can also output numbers, and perform
mathematical calculations:
There is also Write() method, which is similar to
WriteLine().
The only difference is that it does not insert a new
line at the end of the output:
C# COMMENTS
Comments can be used to explain C# code, and
make it more readable. It can also be used to
prevent execution when testing alternative code.
SINGLE-LINE COMMENTS
Single-line comments start with two forward
slashes ( // ).
Any text between // and the end of the line is
ignored by C# (will not be executed).
C# COMMENTS
This example uses a single-line comment before
a line of code:
This example uses a single-line comment at the
end of a line of code:
C# COMMENTS
MULTI-LINE COMMENTS
• Multi-line comments start with /* and ends with
*/.
• Any text between /* and */ will be ignored by C#.
This Example uses a multi-line comment (a
comment block) to explain the code:
C# COMMENTS
Single or Multi-line comments?
It is up to you which one you want to use. Normally,
we use // for short comments, and /**/ for long
comments.
C# VARIABLES
Variables are containers for storing data values.
In C#, there are different types of variables (defined
with different keywords), for example:
• INT – Stores integers (whole numbers), without decimals,
such as 123 or -123.
• DOUBLE – Stores floating point numbers, with decimals,
such as 19.99 or -19.99.
• CHAR – Stores single characters, such as ‘a’ or ‘B’. Char
values are surrounded by single quotes.
• STRING – Stores text, such as “Hello World”. String values
are surrounded by double quotes.
• BOOL – Stores values with two states: True and False
C# VARIABLES
DECLARING (Creating) VARIABLES
To create a variable, you must specify the type and assign it
a value:
Where type is a C# Data Type (such as int or string), and
variableName is the name of the variable (such as x or
name). The equal sign is used to assign values to the
variable.
C# VARIABLES
DECLARING (Creating) VARIABLES
To create a variable that should store text, look at the
following example:
Create a variable called name of type string and assign it
the value “John”:
C# VARIABLES
DECLARING (Creating) VARIABLES
To create a variable that should store number, look at the
following example:
Create a variable called myNum of type int and assign it the
value 15:
C# VARIABLES
DECLARING (Creating) VARIABLES
You can also declare a variable without assigning the value,
and assign the value later:
C# VARIABLES
DECLARING (Creating) VARIABLES
You can assign a new value to an existing variable, it will
overwrite the previous value:
Change the value of myNum to 20:
C# VARIABLES
DECLARING (Creating) VARIABLES
A demonstration of how to declare variables of other types:
C# CONSTANTS
If you don’t want others (or yourself) to overwrite existing
values, you can add the const keyword in front of the
variable type.
This will declare the variable as “constant”, which means
unchangeable and read-only:
C# CONSTANTS
The const keyword is useful when you want a
variable to always store the same value, so that
others (or yourself) won’t mess up your code. An
example that is often referred to as a constant, is PI
(3.14159…).
Note: You cannot declare a constant variable
without assigning the value. If you do, an error will
occur: A const field requires a value to be provided.
C# DISPLAY VARIABLES
The WriteLine() method is often used to display variable
values to the console window:
To combine both text and a variable, use the + character:
C# DISPLAY VARIABLES
You can also use the + character to add a variable to
another variable:
C# DISPLAY VARIABLES
For numeric values, the + character works as a
mathematical operator (notice that we use int (integer)
variables here):
From the example above, you can expect:
x stores the value 5
y stores the value 6
Then we use the WriteLine() method to display the value of x
+ y, which is 11.
C# DECLARE MANY VARIABLES
To declare more than one variable of the same type, use a
comma-separated list:
You can also assign the same value to multiple variables in
one line:
C# IDENTIFIERS
All C# variables must be identified with unique names.
These unique names are called identifiers.
Identifiers can be short names (like x and y) or more
descriptive names (age, sum, totalVolume).
Note: It is recommended to use descriptive names in order
to create understandable and maintainable code:
C# IDENTIFIERS
The general rules for naming variables are:
• Names can contain letters, digits and the underscore
character (_)
• Names must begin with a letter
• Names should start with a lowercase letter and it cannot
contain whitespace
• Names are case sensitive (“MyVar” and “myvar” are
different variables)
• Reserved words (like C# keywords, such as int or double)
cannot be used as names

More Related Content

Similar to A POWERPOINT PRESENTATION ABOUT INTRODUCTION TO C# (20)

PPT
Csharp_mahesh
Ananthu Mahesh
 
DOCX
C-sharping.docx
LenchoMamudeBaro
 
PPT
Synapseindia dot net development
Synapseindiappsdevelopment
 
PPTX
Chapter3: fundamental programming
Ngeam Soly
 
PDF
Chapter two Fundamentals of C# programming
ketemakifle1
 
PPT
Basics1
phanleson
 
PPTX
C#unit4
raksharao
 
DOCX
Unit 1 question and answer
Vasuki Ramasamy
 
PPTX
c# at f#
Harry Balois
 
PPTX
C# AND F#
Harry Balois
 
PPTX
Chapter 2 c#
megersaoljira
 
PDF
C Sharp: Basic to Intermediate Part 01
Zafor Iqbal
 
PPTX
Introduction to C#
Raghuveer Guthikonda
 
PDF
Learn C# programming - Program Structure & Basic Syntax
Eng Teong Cheah
 
PPTX
Notes(1).pptx
InfinityWorld3
 
PPTX
C# lecture 1: Introduction to Dot Net Framework
Dr.Neeraj Kumar Pandey
 
PPTX
#c training and knowlege of c-sharp program.pptx
ndimk1818
 
PPT
Csphtp1 03
HUST
 
PDF
Understanding C# in .NET
mentorrbuddy
 
PPTX
introduction to c #
Sireesh K
 
Csharp_mahesh
Ananthu Mahesh
 
C-sharping.docx
LenchoMamudeBaro
 
Synapseindia dot net development
Synapseindiappsdevelopment
 
Chapter3: fundamental programming
Ngeam Soly
 
Chapter two Fundamentals of C# programming
ketemakifle1
 
Basics1
phanleson
 
C#unit4
raksharao
 
Unit 1 question and answer
Vasuki Ramasamy
 
c# at f#
Harry Balois
 
C# AND F#
Harry Balois
 
Chapter 2 c#
megersaoljira
 
C Sharp: Basic to Intermediate Part 01
Zafor Iqbal
 
Introduction to C#
Raghuveer Guthikonda
 
Learn C# programming - Program Structure & Basic Syntax
Eng Teong Cheah
 
Notes(1).pptx
InfinityWorld3
 
C# lecture 1: Introduction to Dot Net Framework
Dr.Neeraj Kumar Pandey
 
#c training and knowlege of c-sharp program.pptx
ndimk1818
 
Csphtp1 03
HUST
 
Understanding C# in .NET
mentorrbuddy
 
introduction to c #
Sireesh K
 

Recently uploaded (20)

PDF
Zoology (Animal Physiology) practical Manual
raviralanaresh2
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPSX
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PDF
IMP NAAC REFORMS 2024 - 10 Attributes.pdf
BHARTIWADEKAR
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PDF
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPTX
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
Zoology (Animal Physiology) practical Manual
raviralanaresh2
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
IMP NAAC REFORMS 2024 - 10 Attributes.pdf
BHARTIWADEKAR
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
Ad

A POWERPOINT PRESENTATION ABOUT INTRODUCTION TO C#

  • 2. WHY USE C#? C# is pronounced "C-Sharp". It is an object-oriented programming language created by Microsoft that runs on the .NET Framework. C# has roots from the C family, and the language is close to other popular languages like C++ and Java. The first version was released in year 2002. The latest version, C# 11, was released in November 2022.
  • 3. WHY USE C#? C# is used for: • Mobile applications • Desktop applications • Web applications • Web services • Web sites • Games • VR • Database applications • And much, much more!
  • 4. WHY USE C#? • It is one of the most popular programming language in the world • It is easy to learn and simple to use • It has a huge community support • C# is an object oriented language which gives a clear structure to programs and allows code to be reused, lowering development costs • As C# is close to C, C++ and Java, it makes it easy for programmers to switch to C# or vice versa
  • 5. C# IDE • The easiest way to get started with C#, is to use an IDE. • An IDE (Integrated Development Environment) is used to edit and compile code. • Applications written in C# use the .NET Framework, so we will use Visual Studio, as the program, the framework, and the language, are all created by Microsoft.
  • 7. C# SYNTAX Line 1: Using System means that we can use classes from the System namespace. Line 2: A blank line. C# ignores white space. However, multiple lines makes the code more readable. Line 3: namespace is used to organize your code, and it is a container for classes and other namespaces. Line 4: the curly braces { } marks the beginning and the end of a block of code. Line 5: 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 the class Program.
  • 8. C# SYNTAX Line 7: 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. You will get to know them bit by bit. Line 9: Console is a class of the System namespace, which has a WriteLine() method that is used to output/print text. In our example it will output “Hello World!”. If you omit the using System line, you would have to write System.Console.WriteLine() to print/output text.
  • 9. C# SYNTAX Note: Every C# statement ends with a semicolon ; Note: C# is case-sensitive: “MyClass” and “myclass” has different meaning or use Note: Unlike Java, the name of the C# file does not have to match the class name, but they often do (for better organization). When saving the file, save it using a proper name and add “.cs” to the end of the filename.
  • 10. C# SYNTAX Don’t worry if you don’t understand how using System, namespace and class works. Just think of it as something that (almost) always appears in your program, and that you will learn more about them in a later chapter.
  • 11. C# OUTPUT To output values or print text in C#, you can use the WriteLine() method: To can add as many WriteLine() methods as you want. Note that it will add a new line for each method:
  • 12. C# OUTPUT You can also output numbers, and perform mathematical calculations: There is also Write() method, which is similar to WriteLine(). The only difference is that it does not insert a new line at the end of the output:
  • 13. C# COMMENTS Comments can be used to explain C# code, and make it more readable. It can also be used to prevent execution when testing alternative code. SINGLE-LINE COMMENTS Single-line comments start with two forward slashes ( // ). Any text between // and the end of the line is ignored by C# (will not be executed).
  • 14. C# COMMENTS This example uses a single-line comment before a line of code: This example uses a single-line comment at the end of a line of code:
  • 15. C# COMMENTS MULTI-LINE COMMENTS • Multi-line comments start with /* and ends with */. • Any text between /* and */ will be ignored by C#. This Example uses a multi-line comment (a comment block) to explain the code:
  • 16. C# COMMENTS Single or Multi-line comments? It is up to you which one you want to use. Normally, we use // for short comments, and /**/ for long comments.
  • 17. C# VARIABLES Variables are containers for storing data values. In C#, there are different types of variables (defined with different keywords), for example: • INT – Stores integers (whole numbers), without decimals, such as 123 or -123. • DOUBLE – Stores floating point numbers, with decimals, such as 19.99 or -19.99. • CHAR – Stores single characters, such as ‘a’ or ‘B’. Char values are surrounded by single quotes. • STRING – Stores text, such as “Hello World”. String values are surrounded by double quotes. • BOOL – Stores values with two states: True and False
  • 18. C# VARIABLES DECLARING (Creating) VARIABLES To create a variable, you must specify the type and assign it a value: Where type is a C# Data Type (such as int or string), and variableName is the name of the variable (such as x or name). The equal sign is used to assign values to the variable.
  • 19. C# VARIABLES DECLARING (Creating) VARIABLES To create a variable that should store text, look at the following example: Create a variable called name of type string and assign it the value “John”:
  • 20. C# VARIABLES DECLARING (Creating) VARIABLES To create a variable that should store number, look at the following example: Create a variable called myNum of type int and assign it the value 15:
  • 21. C# VARIABLES DECLARING (Creating) VARIABLES You can also declare a variable without assigning the value, and assign the value later:
  • 22. C# VARIABLES DECLARING (Creating) VARIABLES You can assign a new value to an existing variable, it will overwrite the previous value: Change the value of myNum to 20:
  • 23. C# VARIABLES DECLARING (Creating) VARIABLES A demonstration of how to declare variables of other types:
  • 24. C# CONSTANTS If you don’t want others (or yourself) to overwrite existing values, you can add the const keyword in front of the variable type. This will declare the variable as “constant”, which means unchangeable and read-only:
  • 25. C# CONSTANTS The const keyword is useful when you want a variable to always store the same value, so that others (or yourself) won’t mess up your code. An example that is often referred to as a constant, is PI (3.14159…). Note: You cannot declare a constant variable without assigning the value. If you do, an error will occur: A const field requires a value to be provided.
  • 26. C# DISPLAY VARIABLES The WriteLine() method is often used to display variable values to the console window: To combine both text and a variable, use the + character:
  • 27. C# DISPLAY VARIABLES You can also use the + character to add a variable to another variable:
  • 28. C# DISPLAY VARIABLES For numeric values, the + character works as a mathematical operator (notice that we use int (integer) variables here): From the example above, you can expect: x stores the value 5 y stores the value 6 Then we use the WriteLine() method to display the value of x + y, which is 11.
  • 29. C# DECLARE MANY VARIABLES To declare more than one variable of the same type, use a comma-separated list: You can also assign the same value to multiple variables in one line:
  • 30. C# IDENTIFIERS All C# variables must be identified with unique names. These unique names are called identifiers. Identifiers can be short names (like x and y) or more descriptive names (age, sum, totalVolume). Note: It is recommended to use descriptive names in order to create understandable and maintainable code:
  • 31. C# IDENTIFIERS The general rules for naming variables are: • Names can contain letters, digits and the underscore character (_) • Names must begin with a letter • Names should start with a lowercase letter and it cannot contain whitespace • Names are case sensitive (“MyVar” and “myvar” are different variables) • Reserved words (like C# keywords, such as int or double) cannot be used as names