SlideShare a Scribd company logo
Learn C# Programming
Encapsulation & Methods
Eng Teong Cheah
Microsoft MVP in Visual Studio &
Development Technologies
Agenda
•Encapsulation
•Methods
C# - Encapsulation
C# - Encapsulation
Encapsulation is defined ‘as the process of enclosing one or more
items within a physical or logical package’. Encapsulation, in object
oriented programming methodology, prevents access to
implementation details.
Abstraction and encapsulation are related features in object oriented
programming. Abstraction allows making relevant information visible
and encapsulation enables a programmer to implement the desired
level of abstraction.
C# - Encapsulation
Encapsulation is implemented by using access specifiers. An access
specifier defines the scope and visibility of a class member. C#
supports the following access specifiers:
- Public
- Private
- Protected
- Internal
- Protected internal
C# - Encapsulation
Public Access Specifier
Public access specifier allows a class to expose its member variables
and member functions to other functions and objects. Any public
member can be accessed from outside the class.
Demo
C# - Encapsulation
Priavte Access Specifier
Private access specifier allows a class to hide its member variables
and member functions from other functions and objects. Only
functions of the same class can access its private members. Even an
instance of a class cannot access its private members.
Demo
C# - Encapsulation
Protected Access Specifier
Protected access specifier allows a child class to access the member
variables and member functions of its base class. This way it helps in
implementing inheritance.
C# - Encapsulation
Internal Access Specifier
Internal access specifier allows a class to expose its member variables
and member functions to other functions and objects in the current
assembly. In other words, any member with internal access specifier
can be accessed from any class or method defined within the
application in which the member is defined.
Demo
C# - Encapsulation
Protected Internal Access Specifier
The protected internal access specifier allows a class to hide its
member variables and member functions from other class objects
and functions, except a child class within the same application. This is
also used while implementing inheritance.
C# - Methods
C# - Methods
A method is a group of statements that together perform a task.
Every C# program has at least one class with a method name Main.
To use a method, you need to:
- Define the method
- Call the method
C# - Methods
Defining Methods in C#
When you define a method, you basically declare the elements of it
structure. The syntax for defining a method in C# is as follows:
<Access Specifier> <Return Type> <Method Name>(Parameter List)
{
Method Body
}
C# - Methods
Following are the various elements of a method:
- Access Specifier: This determines the visibility of a variable or a
method from another class.
- Return type: A method may return a value. The return type is the
data type of the value the method returns. If the method is not
returning any values, then the return type is void.
- Method name: Method name is a unique identifier and it is case
sensitive. It cannot be same as any other identifier declared in the
class.
C# - Methods
- Parameter list: Enclosed between parantheses, the parameters are
used to pass and receive data from a method. The parameter list
refers to the type, order, and number of the parameters of a
method. Parameters are optional; that is, a method may contain no
parameters.
- Method body: This contains the set of instructions needed to
complete the required activity.
C# - Methods
Example
Following code snippet shows a function FindMax that takes two
integer values and returns the larger of the two. It has public access
specifier, so it can be accessed from outside the class using an
instance of the class.
C# - Methods
class NumberManipulator
{
public int FindMax(int num1, int num2)
{
/* local variable declaration */
int result;
if (num1 > num2)
result = num1;
else
result = num2;
return result;
}
...
}
Demo: Calling Methods in
C#
Demo:Recursive Method
Call
C# - Passing Parameters
to a Method
C# -Passing Parameters to a Method
When method with parameters is called, you need to pass the
parameters to the method. There are three ways that parameters can
be passed to a method:
- Value parameters
- Reference parameters
- Output parameters
C# -Passing Parameters to a Method
Value parameters
This is the default mechanism for passing parameters to a method. In
this mechanism, when a method is called, a new storage location is
created for each value parameter.
The values of the actual parameters are copied into them. Hence, the
changes made to the parameter inside the method have no effect on
the argument.
Demo: Value parameters
C# -Passing Parameters to a Method
Reference parameters
A reference parameter is a reference to a memory location of a
variable. When you pass parameters by reference, unlike value
parameters, a new storage location is not created for these
parameters. The reference parameters represent the same memory
location as the actual parameters that are supplied to the method.
Demo: Reference
parameters
C# -Passing Parameters to a Method
Output parameters
A return statements can be used for returning only one value from a
function. However, using output parameters, you can return two
values from a function. Output parameters are similar to reference
parameters, excepts that they transfer data out of the method rather
than into it.
Demo: Output parameters
Related Content
•TutorialsPoint
www.tutorialspoint.com
Thank You
Ad

Recommended

CS3391 -OOP -UNIT – II NOTES FINAL.pdf
CS3391 -OOP -UNIT – II NOTES FINAL.pdf
AALIM MUHAMMED SALEGH COLLEGE OF ENGINEERING
 
C# Encapsulation
C# Encapsulation
Prem Kumar Badri
 
Methods in java
Methods in java
chauhankapil
 
Delegates and events in C#
Delegates and events in C#
Dr.Neeraj Kumar Pandey
 
Constructor in java
Constructor in java
Pavith Gunasekara
 
C# Exceptions Handling
C# Exceptions Handling
sharqiyem
 
Java Data Types
Java Data Types
Spotle.ai
 
Classes, objects in JAVA
Classes, objects in JAVA
Abhilash Nair
 
Arrays in Java
Arrays in Java
Abhilash Nair
 
Inheritance in java
Inheritance in java
yash jain
 
Classes and data abstraction
Classes and data abstraction
Hoang Nguyen
 
Principal Sources of Optimization in compiler design
Principal Sources of Optimization in compiler design
LogsAk
 
JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
Type casting
Type casting
Ruchika Sinha
 
Lecture_7-Encapsulation in Java.pptx
Lecture_7-Encapsulation in Java.pptx
ShahinAhmed49
 
Access specifier
Access specifier
zindadili
 
Dbms Notes Lecture 9 : Specialization, Generalization and Aggregation
Dbms Notes Lecture 9 : Specialization, Generalization and Aggregation
BIT Durg
 
itft-Decision making and branching in java
itft-Decision making and branching in java
Atul Sehdev
 
Introduction to Object Oriented Programming
Introduction to Object Oriented Programming
Moutaz Haddara
 
File in C language
File in C language
Manash Kumar Mondal
 
Exception handling
Exception handling
PhD Research Scholar
 
classes and objects in C++
classes and objects in C++
HalaiHansaika
 
Type conversion
Type conversion
PreethaPreetha5
 
SQL Views
SQL Views
baabtra.com - No. 1 supplier of quality freshers
 
PL/SQL TRIGGERS
PL/SQL TRIGGERS
Lakshman Basnet
 
Super keyword in java
Super keyword in java
Hitesh Kumar
 
Chapter2 Encapsulation (Java)
Chapter2 Encapsulation (Java)
Dyah Fajar Nur Rohmah
 
Functions in C++
Functions in C++
Mohammed Sikander
 
C++ classes tutorials
C++ classes tutorials
akreyi
 
Application package
Application package
JAYAARC
 

More Related Content

What's hot (20)

Arrays in Java
Arrays in Java
Abhilash Nair
 
Inheritance in java
Inheritance in java
yash jain
 
Classes and data abstraction
Classes and data abstraction
Hoang Nguyen
 
Principal Sources of Optimization in compiler design
Principal Sources of Optimization in compiler design
LogsAk
 
JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
Type casting
Type casting
Ruchika Sinha
 
Lecture_7-Encapsulation in Java.pptx
Lecture_7-Encapsulation in Java.pptx
ShahinAhmed49
 
Access specifier
Access specifier
zindadili
 
Dbms Notes Lecture 9 : Specialization, Generalization and Aggregation
Dbms Notes Lecture 9 : Specialization, Generalization and Aggregation
BIT Durg
 
itft-Decision making and branching in java
itft-Decision making and branching in java
Atul Sehdev
 
Introduction to Object Oriented Programming
Introduction to Object Oriented Programming
Moutaz Haddara
 
File in C language
File in C language
Manash Kumar Mondal
 
Exception handling
Exception handling
PhD Research Scholar
 
classes and objects in C++
classes and objects in C++
HalaiHansaika
 
Type conversion
Type conversion
PreethaPreetha5
 
SQL Views
SQL Views
baabtra.com - No. 1 supplier of quality freshers
 
PL/SQL TRIGGERS
PL/SQL TRIGGERS
Lakshman Basnet
 
Super keyword in java
Super keyword in java
Hitesh Kumar
 
Chapter2 Encapsulation (Java)
Chapter2 Encapsulation (Java)
Dyah Fajar Nur Rohmah
 
Functions in C++
Functions in C++
Mohammed Sikander
 
Inheritance in java
Inheritance in java
yash jain
 
Classes and data abstraction
Classes and data abstraction
Hoang Nguyen
 
Principal Sources of Optimization in compiler design
Principal Sources of Optimization in compiler design
LogsAk
 
JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
Lecture_7-Encapsulation in Java.pptx
Lecture_7-Encapsulation in Java.pptx
ShahinAhmed49
 
Access specifier
Access specifier
zindadili
 
Dbms Notes Lecture 9 : Specialization, Generalization and Aggregation
Dbms Notes Lecture 9 : Specialization, Generalization and Aggregation
BIT Durg
 
itft-Decision making and branching in java
itft-Decision making and branching in java
Atul Sehdev
 
Introduction to Object Oriented Programming
Introduction to Object Oriented Programming
Moutaz Haddara
 
classes and objects in C++
classes and objects in C++
HalaiHansaika
 
Super keyword in java
Super keyword in java
Hitesh Kumar
 

Similar to Learn C# Programming - Encapsulation & Methods (20)

C++ classes tutorials
C++ classes tutorials
akreyi
 
Application package
Application package
JAYAARC
 
Methods in C# | C# Methods Tutorial | C# Tutorial for Beginners | Learn C# Pr...
Methods in C# | C# Methods Tutorial | C# Tutorial for Beginners | Learn C# Pr...
Simplilearn
 
Lecture-Midterm .pptx
Lecture-Midterm .pptx
lorenzocarhl
 
Introduction to objective c
Introduction to objective c
Sunny Shaikh
 
Methods in C#
Methods in C#
Prasanna Kumar SM
 
Presentation 3rd
Presentation 3rd
Connex
 
Web Technology-Method .pdf
Web Technology-Method .pdf
nandiaditi2010
 
C# classes objects
C# classes objects
Dr.Neeraj Kumar Pandey
 
C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01
Zafor Iqbal
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT
Ajay Chimmani
 
Learn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & Inheritance
Eng Teong Cheah
 
Explain Delegates step by step.
Explain Delegates step by step.
Questpond
 
Exhibit design and programming skills to build and automate business solution...
Exhibit design and programming skills to build and automate business solution...
sramani6
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
vekariyakashyap
 
I assignmnt(oops)
I assignmnt(oops)
Jay Patel
 
Unit2_4.pptx Object Oriented Concepts .
Unit2_4.pptx Object Oriented Concepts .
Priyanka Jadhav
 
Evolution of c# - by K.Jegan
Evolution of c# - by K.Jegan
talenttransform
 
2 Object-oriented programghgrtrdwwe.pptx
2 Object-oriented programghgrtrdwwe.pptx
RamaDalabeh
 
Ap Power Point Chpt4
Ap Power Point Chpt4
dplunkett
 
C++ classes tutorials
C++ classes tutorials
akreyi
 
Application package
Application package
JAYAARC
 
Methods in C# | C# Methods Tutorial | C# Tutorial for Beginners | Learn C# Pr...
Methods in C# | C# Methods Tutorial | C# Tutorial for Beginners | Learn C# Pr...
Simplilearn
 
Lecture-Midterm .pptx
Lecture-Midterm .pptx
lorenzocarhl
 
Introduction to objective c
Introduction to objective c
Sunny Shaikh
 
Presentation 3rd
Presentation 3rd
Connex
 
Web Technology-Method .pdf
Web Technology-Method .pdf
nandiaditi2010
 
C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01
Zafor Iqbal
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT
Ajay Chimmani
 
Learn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & Inheritance
Eng Teong Cheah
 
Explain Delegates step by step.
Explain Delegates step by step.
Questpond
 
Exhibit design and programming skills to build and automate business solution...
Exhibit design and programming skills to build and automate business solution...
sramani6
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
vekariyakashyap
 
I assignmnt(oops)
I assignmnt(oops)
Jay Patel
 
Unit2_4.pptx Object Oriented Concepts .
Unit2_4.pptx Object Oriented Concepts .
Priyanka Jadhav
 
Evolution of c# - by K.Jegan
Evolution of c# - by K.Jegan
talenttransform
 
2 Object-oriented programghgrtrdwwe.pptx
2 Object-oriented programghgrtrdwwe.pptx
RamaDalabeh
 
Ap Power Point Chpt4
Ap Power Point Chpt4
dplunkett
 
Ad

More from Eng Teong Cheah (20)

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

Recently uploaded (20)

"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
The Growing Value and Application of FME & GenAI
The Growing Value and Application of FME & GenAI
Safe Software
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
Techniques for Automatic Device Identification and Network Assignment.pdf
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
 
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
All Things Open
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
The Growing Value and Application of FME & GenAI
The Growing Value and Application of FME & GenAI
Safe Software
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
Techniques for Automatic Device Identification and Network Assignment.pdf
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
 
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
All Things Open
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 

Learn C# Programming - Encapsulation & Methods

  • 1. Learn C# Programming Encapsulation & Methods Eng Teong Cheah Microsoft MVP in Visual Studio & Development Technologies
  • 4. C# - Encapsulation Encapsulation is defined ‘as the process of enclosing one or more items within a physical or logical package’. Encapsulation, in object oriented programming methodology, prevents access to implementation details. Abstraction and encapsulation are related features in object oriented programming. Abstraction allows making relevant information visible and encapsulation enables a programmer to implement the desired level of abstraction.
  • 5. C# - Encapsulation Encapsulation is implemented by using access specifiers. An access specifier defines the scope and visibility of a class member. C# supports the following access specifiers: - Public - Private - Protected - Internal - Protected internal
  • 6. C# - Encapsulation Public Access Specifier Public access specifier allows a class to expose its member variables and member functions to other functions and objects. Any public member can be accessed from outside the class.
  • 8. C# - Encapsulation Priavte Access Specifier Private access specifier allows a class to hide its member variables and member functions from other functions and objects. Only functions of the same class can access its private members. Even an instance of a class cannot access its private members.
  • 10. C# - Encapsulation Protected Access Specifier Protected access specifier allows a child class to access the member variables and member functions of its base class. This way it helps in implementing inheritance.
  • 11. C# - Encapsulation Internal Access Specifier Internal access specifier allows a class to expose its member variables and member functions to other functions and objects in the current assembly. In other words, any member with internal access specifier can be accessed from any class or method defined within the application in which the member is defined.
  • 12. Demo
  • 13. C# - Encapsulation Protected Internal Access Specifier The protected internal access specifier allows a class to hide its member variables and member functions from other class objects and functions, except a child class within the same application. This is also used while implementing inheritance.
  • 15. C# - Methods A method is a group of statements that together perform a task. Every C# program has at least one class with a method name Main. To use a method, you need to: - Define the method - Call the method
  • 16. C# - Methods Defining Methods in C# When you define a method, you basically declare the elements of it structure. The syntax for defining a method in C# is as follows: <Access Specifier> <Return Type> <Method Name>(Parameter List) { Method Body }
  • 17. C# - Methods Following are the various elements of a method: - Access Specifier: This determines the visibility of a variable or a method from another class. - Return type: A method may return a value. The return type is the data type of the value the method returns. If the method is not returning any values, then the return type is void. - Method name: Method name is a unique identifier and it is case sensitive. It cannot be same as any other identifier declared in the class.
  • 18. C# - Methods - Parameter list: Enclosed between parantheses, the parameters are used to pass and receive data from a method. The parameter list refers to the type, order, and number of the parameters of a method. Parameters are optional; that is, a method may contain no parameters. - Method body: This contains the set of instructions needed to complete the required activity.
  • 19. C# - Methods Example Following code snippet shows a function FindMax that takes two integer values and returns the larger of the two. It has public access specifier, so it can be accessed from outside the class using an instance of the class.
  • 20. C# - Methods class NumberManipulator { public int FindMax(int num1, int num2) { /* local variable declaration */ int result; if (num1 > num2) result = num1; else result = num2; return result; } ... }
  • 23. C# - Passing Parameters to a Method
  • 24. C# -Passing Parameters to a Method When method with parameters is called, you need to pass the parameters to the method. There are three ways that parameters can be passed to a method: - Value parameters - Reference parameters - Output parameters
  • 25. C# -Passing Parameters to a Method Value parameters This is the default mechanism for passing parameters to a method. In this mechanism, when a method is called, a new storage location is created for each value parameter. The values of the actual parameters are copied into them. Hence, the changes made to the parameter inside the method have no effect on the argument.
  • 27. C# -Passing Parameters to a Method Reference parameters A reference parameter is a reference to a memory location of a variable. When you pass parameters by reference, unlike value parameters, a new storage location is not created for these parameters. The reference parameters represent the same memory location as the actual parameters that are supplied to the method.
  • 29. C# -Passing Parameters to a Method Output parameters A return statements can be used for returning only one value from a function. However, using output parameters, you can return two values from a function. Output parameters are similar to reference parameters, excepts that they transfer data out of the method rather than into it.