SlideShare a Scribd company logo
Learn C# Programming
Program Structure & Basic Syntax
Eng Teong Cheah
Microsoft MVP in Visual Studio &
Development Technologies
Agenda
•Program Structure
•Basic Syntax
C# - Program Structure
C# - Program Structure
Before we study basic building blocks of the C# programming
language, let us look at a bare minimum C# program structure so
that we can take it as a reference in upcoming chapters.
C# - Program Structure
Create Hello World Program
A C# program consists of the following parts:
- Namespace declaration
- A class
- Class methods
- Class attributes
- A Main method
- Statements and Expressions
- Comments
C# - Program Structure
Let us look at a simple code that prints the words “Hello World”:
When this code is compiled and executed, it produces the following result:
Hello World
C# - Program Structure
Let us look at the various parts of the given program:
The first line of the program using System; - the using keyword is
used to include the System namespace in the program. A program
generally has multiple using statements.
C# - Program Structure
Let us look at the various parts of the given program:
The next line has the namespace declaration. A namespace is a
collection of classes. The HelloWorldApplication namespace
contains the class HelloWorld.
C# - Program Structure
Let us look at the various parts of the given program:
The next line has a class declaration, the class HelloWorld contains
the data and method definitions that your program uses. Classes
generally contain multiple methods. Methods define the behaviour
of the class. However, the HelloWorld class has only one method
Main.
C# - Program Structure
Let us look at the various parts of the given program:
The next line defines the Main method, which is the entry point for
all C# programs. The Main method states what the class does
when executed.
C# - Program Structure
Let us look at the various parts of the given program:
The next line /*..*/ is ignored by the compiler and it is put to add
comments in the program.
C# - Program Structure
Let us look at the various parts of the given program:
The Main method specified its behaviour with the statement
Console.WriteLine (“Hello World”);
WriteLine is a method of the Console class defined in the System
namespace. This statement causes the message “Hello World” to
be displayed on the screen.
C# - Program Structure
Let us look at the various parts of the given program:
The last line Console.ReadKey(); is for the VS.NET Users. This
makes the program wait for a key press and it prevents the screen
from running and closing quickly when the program is launched
from Visual Studio .NET.
C# - Program Structure
It is worth to note the following points:
- C# is case sensitive
- All statements and expression must end with a semicolon(;)
- The program execution starts at the Main method.
- Unlike Java, program file name could be different from the
class name.
Demo
C# - Basic Syntax
C# - Basic Syntax
C# is an object-oriented programming language. In Object-
Oriented Programming methodology, a program consists of
various objects that interact with each other by means of
actions. The actions that an object may take are called
methods. Objects of the same kind are said to have the
same type or, are said to be in the same class.
C# - Basic Syntax
For example, let us consider a Rectangle object. It has
attributes such as length and width. Depending upon the
design, it may need ways for accepting the values of these
attributes, calculating the area, and displaying details.
Lets us look at implementation of a Rectangle and discuss
C# basic syntax:
C# - Basic Syntax
Length: 4.5
Width: 3.5
Area: 15.75
When the code is compiled and
executed, it produces the
following result:
C# - Basic Syntax
The using Keyword
The first statement in any C# program is
using System;
The using keyword is used for including the
namespace in the program. A program can include
multiple using statements.
C# - Basic Syntax
The class Keyword
The class keyword is used for declaring a class.
C# - Basic Syntax
Member Variables
Variables are attributes or data members of a class,
used for storing data. In the preceding program, the
Rectangle class has two member variables named
length and width.
C# - Basic Syntax
Member Functions
Functions are set of statements that perform a specific
task. The member functions of a class are declared
within the class. Our sample class Rectangle contains
three member functions: AcceptDetails, GetArea and
Display.
C# - Basic Syntax
Instantiating a Class
In the preceding program, the class ExecuteRectangle
contains the Main() method and instantiates the
Rectangle class.
C# - Basic Syntax
Identifiers
An identifier is a name used to identify a class, variable, function,
or any other user-defined item. The basic rules for naming
classes in C# are as follows:
- A name must begin with a letter that could be followed by a
sequence of letters, digits (0-9) or underscore. The first
character in an identifier cannot be a digit.
C# - Basic Syntax
Identifiers
An identifier is a name used to identify a class, variable, function,
or any other user-defined item. The basic rules for naming
classes in C# are as follows:
-It must not contain any embedded space or symbol such as ? -
+ ! @ # % ^ & * ( ) [ ] { } . ; : “ ‘ / and . However, an underscore
(_) can be used.
C# - Basic Syntax
Identifiers
An identifier is a name used to identify a class, variable, function,
or any other user-defined item. The basic rules for naming
classes in C# are as follows:
- It should not be a C# keyword.
C# - Basic Syntax
C# Keywords
Keywords are reserved words predefined to the C# compiler.
Theses keywords cannot be used as identifiers. However, if you
want to use these keywords as identifiers, you may prefix the
keyword with the @ character.
In C#, some identifiers have special meaning in context of code,
such as get and set are called contextual keywords.
C# - Basic Syntax
The following table lists the
reserved keywords and
contextual keywords in C#:
C# - Basic Syntax
The following table lists the reserved keywords and contextual
keywords in C#:
Demo
Related Content
•TutorialsPoint
www.tutorialspoint.com
Thank You

More Related Content

What's hot (20)

PPTX
Components of .NET Framework
Roshith S Pai
 
PPTX
Critical systems engineering
sommerville-videos
 
PDF
Java basic concept
University of Potsdam
 
PPT
SQA-Plan.ppt
VijayAgrahari3
 
PPT
Introduction to .NET Framework
Raghuveer Guthikonda
 
PPTX
C# 101: Intro to Programming with C#
Hawkman Academy
 
PPT
Introduction to Visual Studio.NET
Dutch Dasanaike {LION}
 
PPTX
Activity Diagram Examples by Creately
Creately
 
PDF
Automotive embedded systems part3 v1
Keroles karam khalil
 
PPTX
Namespaces in C#
yogita kachve
 
PPTX
Introduction to c#
Ravi Jakashania
 
PPT
Black box & white-box testing technique
SivaprasanthRentala1975
 
PDF
Learn C# Programming - Data Types & Type Conversion
Eng Teong Cheah
 
PPTX
Introduction To C#
rahulsahay19
 
PPTX
Unit 3. Input and Output
Ashim Lamichhane
 
PPTX
Java abstract class & abstract methods
Shubham Dwivedi
 
PPSX
C# - Part 1
Md. Mahedee Hasan
 
PPTX
VB.NET:An introduction to Namespaces in .NET framework
Richa Handa
 
PPT
7.data types in c#
Zeeshan Ahmad
 
PPT
Chapter 4 5
ahmed22dg
 
Components of .NET Framework
Roshith S Pai
 
Critical systems engineering
sommerville-videos
 
Java basic concept
University of Potsdam
 
SQA-Plan.ppt
VijayAgrahari3
 
Introduction to .NET Framework
Raghuveer Guthikonda
 
C# 101: Intro to Programming with C#
Hawkman Academy
 
Introduction to Visual Studio.NET
Dutch Dasanaike {LION}
 
Activity Diagram Examples by Creately
Creately
 
Automotive embedded systems part3 v1
Keroles karam khalil
 
Namespaces in C#
yogita kachve
 
Introduction to c#
Ravi Jakashania
 
Black box & white-box testing technique
SivaprasanthRentala1975
 
Learn C# Programming - Data Types & Type Conversion
Eng Teong Cheah
 
Introduction To C#
rahulsahay19
 
Unit 3. Input and Output
Ashim Lamichhane
 
Java abstract class & abstract methods
Shubham Dwivedi
 
C# - Part 1
Md. Mahedee Hasan
 
VB.NET:An introduction to Namespaces in .NET framework
Richa Handa
 
7.data types in c#
Zeeshan Ahmad
 
Chapter 4 5
ahmed22dg
 

Viewers also liked (19)

PPTX
Xamarin - First Application
Eng Teong Cheah
 
PPTX
Introduction of C#
Eng Teong Cheah
 
PPT
Difference between Java and c#
Sagar Pednekar
 
PPT
C#/.NET Little Wonders
BlackRabbitCoder
 
PPTX
.NET and C# Introduction
Siraj Memon
 
PDF
Learn C# Programming - Variables & Constants
Eng Teong Cheah
 
PPT
Agile Methodologies
Kenny Nguyen
 
PDF
Xamarin: Namespace and Classes
Eng Teong Cheah
 
PDF
Xamarin: Branching and Looping
Eng Teong Cheah
 
PDF
Xamarin: C# Methods
Eng Teong Cheah
 
PPTX
Academy PRO: Unity 3D. Scripting
Binary Studio
 
PDF
Unity 3d scripting tutorial
Blaž Gregorčič
 
PDF
Xamarin: Inheritance and Polymorphism
Eng Teong Cheah
 
PPT
Chapter 13 - Inheritance and Polymorphism
Eduardo Bergavera
 
PDF
CP Handout#2
trupti1976
 
PPTX
Agile Retrospectives
Hawkman Academy
 
PPT
8.3 program structure (1 hour)
akmalfahmi
 
PDF
CP Handout#5
trupti1976
 
PPTX
Constructs (Programming Methodology)
Jyoti Bhardwaj
 
Xamarin - First Application
Eng Teong Cheah
 
Introduction of C#
Eng Teong Cheah
 
Difference between Java and c#
Sagar Pednekar
 
C#/.NET Little Wonders
BlackRabbitCoder
 
.NET and C# Introduction
Siraj Memon
 
Learn C# Programming - Variables & Constants
Eng Teong Cheah
 
Agile Methodologies
Kenny Nguyen
 
Xamarin: Namespace and Classes
Eng Teong Cheah
 
Xamarin: Branching and Looping
Eng Teong Cheah
 
Xamarin: C# Methods
Eng Teong Cheah
 
Academy PRO: Unity 3D. Scripting
Binary Studio
 
Unity 3d scripting tutorial
Blaž Gregorčič
 
Xamarin: Inheritance and Polymorphism
Eng Teong Cheah
 
Chapter 13 - Inheritance and Polymorphism
Eduardo Bergavera
 
CP Handout#2
trupti1976
 
Agile Retrospectives
Hawkman Academy
 
8.3 program structure (1 hour)
akmalfahmi
 
CP Handout#5
trupti1976
 
Constructs (Programming Methodology)
Jyoti Bhardwaj
 
Ad

Similar to Learn C# programming - Program Structure & Basic Syntax (20)

PPTX
c#.pptx
JoselitoJMebolos
 
DOCX
csharp.docx
LenchoMamudeBaro
 
PPTX
Structure of a C# Program
Ali Hassan
 
PPTX
C# lecture 1: Introduction to Dot Net Framework
Dr.Neeraj Kumar Pandey
 
PDF
C# c# for beginners crash course master c# programming fast and easy today
Afonso Macedo
 
PPTX
A POWERPOINT PRESENTATION ABOUT INTRODUCTION TO C#
Jhay Deeh
 
PPTX
introduction to c #
Sireesh K
 
PDF
overview of c#
Kandreo Gotro
 
PDF
C For Beginners Crash Course Master C Programming Fast And Easy Today 1st Edi...
kbdmknm1241
 
PPSX
Microsoft C# programming basics
Prognoz Technologies Pvt. Ltd.
 
PPTX
Cordovilla
brianmae002
 
PPTX
CSharp Programming.pptx
AsadullahEman
 
PDF
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdf
MMRF2
 
PPTX
Chapter 2 c#
megersaoljira
 
PPTX
Introduction to C#
Raghuveer Guthikonda
 
PPTX
Csharp introduction
Sireesh K
 
PPT
Ch01
guest7a6cbb3
 
PPTX
Notes(1).pptx
InfinityWorld3
 
PPT
Synapseindia dot net development
Synapseindiappsdevelopment
 
csharp.docx
LenchoMamudeBaro
 
Structure of a C# Program
Ali Hassan
 
C# lecture 1: Introduction to Dot Net Framework
Dr.Neeraj Kumar Pandey
 
C# c# for beginners crash course master c# programming fast and easy today
Afonso Macedo
 
A POWERPOINT PRESENTATION ABOUT INTRODUCTION TO C#
Jhay Deeh
 
introduction to c #
Sireesh K
 
overview of c#
Kandreo Gotro
 
C For Beginners Crash Course Master C Programming Fast And Easy Today 1st Edi...
kbdmknm1241
 
Microsoft C# programming basics
Prognoz Technologies Pvt. Ltd.
 
Cordovilla
brianmae002
 
CSharp Programming.pptx
AsadullahEman
 
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdf
MMRF2
 
Chapter 2 c#
megersaoljira
 
Introduction to C#
Raghuveer Guthikonda
 
Csharp introduction
Sireesh K
 
Notes(1).pptx
InfinityWorld3
 
Synapseindia dot net development
Synapseindiappsdevelopment
 
Ad

More from Eng Teong Cheah (20)

PDF
Modern Cross-Platform Apps with .NET MAUI
Eng Teong Cheah
 
PDF
Efficiently Removing Duplicates from a Sorted Array
Eng Teong Cheah
 
PDF
Monitoring Models
Eng Teong Cheah
 
PDF
Responsible Machine Learning
Eng Teong Cheah
 
PDF
Training Optimal Models
Eng Teong Cheah
 
PDF
Deploying Models
Eng Teong Cheah
 
PDF
Machine Learning Workflows
Eng Teong Cheah
 
PDF
Working with Compute
Eng Teong Cheah
 
PDF
Working with Data
Eng Teong Cheah
 
PDF
Experiments & TrainingModels
Eng Teong Cheah
 
PDF
Automated Machine Learning
Eng Teong Cheah
 
PDF
Getting Started with Azure Machine Learning
Eng Teong Cheah
 
PDF
Hacking Containers - Container Storage
Eng Teong Cheah
 
PDF
Hacking Containers - Looking at Cgroups
Eng Teong Cheah
 
PDF
Hacking Containers - Linux Containers
Eng Teong Cheah
 
PDF
Data Security - Storage Security
Eng Teong Cheah
 
PDF
Application Security- App security
Eng Teong Cheah
 
PDF
Application Security - Key Vault
Eng Teong Cheah
 
PDF
Compute Security - Container Security
Eng Teong Cheah
 
PDF
Compute Security - Host Security
Eng Teong Cheah
 
Modern Cross-Platform Apps with .NET MAUI
Eng Teong Cheah
 
Efficiently Removing Duplicates from a Sorted Array
Eng Teong Cheah
 
Monitoring Models
Eng Teong Cheah
 
Responsible Machine Learning
Eng Teong Cheah
 
Training Optimal Models
Eng Teong Cheah
 
Deploying Models
Eng Teong Cheah
 
Machine Learning Workflows
Eng Teong Cheah
 
Working with Compute
Eng Teong Cheah
 
Working with Data
Eng Teong Cheah
 
Experiments & TrainingModels
Eng Teong Cheah
 
Automated Machine Learning
Eng Teong Cheah
 
Getting Started with Azure Machine Learning
Eng Teong Cheah
 
Hacking Containers - Container Storage
Eng Teong Cheah
 
Hacking Containers - Looking at Cgroups
Eng Teong Cheah
 
Hacking Containers - Linux Containers
Eng Teong Cheah
 
Data Security - Storage Security
Eng Teong Cheah
 
Application Security- App security
Eng Teong Cheah
 
Application Security - Key Vault
Eng Teong Cheah
 
Compute Security - Container Security
Eng Teong Cheah
 
Compute Security - Host Security
Eng Teong Cheah
 

Recently uploaded (20)

PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 

Learn C# programming - Program Structure & Basic Syntax

  • 1. Learn C# Programming Program Structure & Basic Syntax Eng Teong Cheah Microsoft MVP in Visual Studio & Development Technologies
  • 3. C# - Program Structure
  • 4. C# - Program Structure Before we study basic building blocks of the C# programming language, let us look at a bare minimum C# program structure so that we can take it as a reference in upcoming chapters.
  • 5. C# - Program Structure Create Hello World Program A C# program consists of the following parts: - Namespace declaration - A class - Class methods - Class attributes - A Main method - Statements and Expressions - Comments
  • 6. C# - Program Structure Let us look at a simple code that prints the words “Hello World”: When this code is compiled and executed, it produces the following result: Hello World
  • 7. C# - Program Structure Let us look at the various parts of the given program: The first line of the program using System; - the using keyword is used to include the System namespace in the program. A program generally has multiple using statements.
  • 8. C# - Program Structure Let us look at the various parts of the given program: The next line has the namespace declaration. A namespace is a collection of classes. The HelloWorldApplication namespace contains the class HelloWorld.
  • 9. C# - Program Structure Let us look at the various parts of the given program: The next line has a class declaration, the class HelloWorld contains the data and method definitions that your program uses. Classes generally contain multiple methods. Methods define the behaviour of the class. However, the HelloWorld class has only one method Main.
  • 10. C# - Program Structure Let us look at the various parts of the given program: The next line defines the Main method, which is the entry point for all C# programs. The Main method states what the class does when executed.
  • 11. C# - Program Structure Let us look at the various parts of the given program: The next line /*..*/ is ignored by the compiler and it is put to add comments in the program.
  • 12. C# - Program Structure Let us look at the various parts of the given program: The Main method specified its behaviour with the statement Console.WriteLine (“Hello World”); WriteLine is a method of the Console class defined in the System namespace. This statement causes the message “Hello World” to be displayed on the screen.
  • 13. C# - Program Structure Let us look at the various parts of the given program: The last line Console.ReadKey(); is for the VS.NET Users. This makes the program wait for a key press and it prevents the screen from running and closing quickly when the program is launched from Visual Studio .NET.
  • 14. C# - Program Structure It is worth to note the following points: - C# is case sensitive - All statements and expression must end with a semicolon(;) - The program execution starts at the Main method. - Unlike Java, program file name could be different from the class name.
  • 15. Demo
  • 16. C# - Basic Syntax
  • 17. C# - Basic Syntax C# is an object-oriented programming language. In Object- Oriented Programming methodology, a program consists of various objects that interact with each other by means of actions. The actions that an object may take are called methods. Objects of the same kind are said to have the same type or, are said to be in the same class.
  • 18. C# - Basic Syntax For example, let us consider a Rectangle object. It has attributes such as length and width. Depending upon the design, it may need ways for accepting the values of these attributes, calculating the area, and displaying details. Lets us look at implementation of a Rectangle and discuss C# basic syntax:
  • 19. C# - Basic Syntax Length: 4.5 Width: 3.5 Area: 15.75 When the code is compiled and executed, it produces the following result:
  • 20. C# - Basic Syntax The using Keyword The first statement in any C# program is using System; The using keyword is used for including the namespace in the program. A program can include multiple using statements.
  • 21. C# - Basic Syntax The class Keyword The class keyword is used for declaring a class.
  • 22. C# - Basic Syntax Member Variables Variables are attributes or data members of a class, used for storing data. In the preceding program, the Rectangle class has two member variables named length and width.
  • 23. C# - Basic Syntax Member Functions Functions are set of statements that perform a specific task. The member functions of a class are declared within the class. Our sample class Rectangle contains three member functions: AcceptDetails, GetArea and Display.
  • 24. C# - Basic Syntax Instantiating a Class In the preceding program, the class ExecuteRectangle contains the Main() method and instantiates the Rectangle class.
  • 25. C# - Basic Syntax Identifiers An identifier is a name used to identify a class, variable, function, or any other user-defined item. The basic rules for naming classes in C# are as follows: - A name must begin with a letter that could be followed by a sequence of letters, digits (0-9) or underscore. The first character in an identifier cannot be a digit.
  • 26. C# - Basic Syntax Identifiers An identifier is a name used to identify a class, variable, function, or any other user-defined item. The basic rules for naming classes in C# are as follows: -It must not contain any embedded space or symbol such as ? - + ! @ # % ^ & * ( ) [ ] { } . ; : “ ‘ / and . However, an underscore (_) can be used.
  • 27. C# - Basic Syntax Identifiers An identifier is a name used to identify a class, variable, function, or any other user-defined item. The basic rules for naming classes in C# are as follows: - It should not be a C# keyword.
  • 28. C# - Basic Syntax C# Keywords Keywords are reserved words predefined to the C# compiler. Theses keywords cannot be used as identifiers. However, if you want to use these keywords as identifiers, you may prefix the keyword with the @ character. In C#, some identifiers have special meaning in context of code, such as get and set are called contextual keywords.
  • 29. C# - Basic Syntax The following table lists the reserved keywords and contextual keywords in C#:
  • 30. C# - Basic Syntax The following table lists the reserved keywords and contextual keywords in C#:
  • 31. Demo