Professional Documents
Culture Documents
C#
Programming
LESSON 5-1
ROMMEL L. DORIN
Contents
Methods
Constructor
Methods in C#
• Syntax:
Methods in C#
• Access_Specifier - It is used to define an access level,
either public or private, etc., to allow other classes to access
the method. If we didn’t mention any access modifier, then
by default, it is private.
• Return_Type - It is used to specify the type of value the
method can return. If the method is not returning any value,
then we need to mention void as the return type.
• Method_Name - It must be a unique name to identify the
method in a class.
• Parameters - The method parameters are useful to send or
receive data from a method, and these method parameters
are enclosed within parentheses and are separated by
commas. If no parameters are required for a method, we
need to define a method with empty parentheses.
Methods in C#
In C#, there are 4 basic types of access modifiers.
• Example:
Methods in C#
• Example:
C# Static Methods
2 Types of methods:
2 Types of methods:
• A nob surrounding by
blades, its brand, the
color of it depicts the
state of the revolving
fan.
• The airflow created by
the fan is said to be its
functionality.
C# Object
• Whereas change in
the position of blades
while revolving
represents the change
of its state.
C# Object
C# Object
• We use the name of
objects along with the
. (dot) operator to
access members of a
class.
C# Object
• Creating multiple
objects from the same
class
C# Object
• Creating objects in a
different class
C# Class Instance Syntax
• Syntax:
• Differences among C#
Variable, Instance (Object)
and Reference
• The C# Variable is nothing but a copy
of a class which is not initialized.
Creating C# constructor
C# Constructor
Types of constructors:
• Parameterless Constructor
• Parameterized Constructor
• Default Constructor
C# Constructor
Parameterless Constructor – a
constructor without parameters.
C# Constructor
Parameterized Constructor – a
constructor can accept parameters.
C# Constructor
Parameterized Constructor – a
constructor can accept parameters.