SlideShare a Scribd company logo
3
Most read
4
Most read
8
Most read
Classes and Objects in C#
 https://www.slideshare.net/adeel02
 A class is a construct that enables you to create your
own custom types by grouping together variables of
other types, methods and events.
 It defines the data and behavior of a type.
 Supports the OOP principle "encapsulation“
 Fields and methods can be::
Instance (or object members)
Static (or class members)
Class definition consists of
 Class declaration
 Data Fields
 Constructors
 Properties
 Methods
class test{
public int a = 5, b = 10;
public void mul(){
Console.Write("The Result of
Multiply is = {0}", a * b);
Console.ReadLine();
}}
Classes
Classes are declared by using the keyword class
followed by the class name and a set of class
members surrounded by curly braces { }.
class House
{
Body
...
}
Basic syntax for class declaration
Class comprises a class header and class body.
class class_name
{
class body
}
Note: No semicolon (;) to terminate class block.
But statements must be terminated with a semicolon ;
 In C#, individual classes and class members need
to be prefixed with visibility modifiers.
 By default, if you declare a member variable (or
anything else) in a class but do not specify its
access level, the member is considered private
and cannot be accessed from outside, i.e. by a
non-member of that class.
 Therefore, to make a member accessible by other
classes, you must declare it as public.
 Object is an abstraction of real world entity.
 Syntax for declaring objects is as follows :
 MyClass objMyClass = new MyClass();
 It can have its own copy of data members.
 It can be passed to a function like normal variables.
 The members of the class can accessed by the object
using the object to member access operator or dot
operator(.).
 Create Object
 Call function and variables with the help of object
 MyClass objMyClass = new MyClass();
 objMycClass.function_name();
 objMycClass.variable;
Constructors
public MyClass(parameters) {...}
• new operator – create an instance of the class
MyClass objMyClass = new MyClass();
public Person()
{
name = null;
age = 0;
}
 class testt{
 public static int a = 5, b = 10;
 public static void mul(){
 Console.Write("The Result of Multiply is = {0}", a
* b);
 Console.ReadLine();
 }}
 MyClass objMyClass1 = new MyClass();
 objMycClass1.function_name();
 MyClass objMyClass2 = new MyClass();
 objMycClass2.function_name();
 MyClass.function_name();
Classes and Objects in C#

More Related Content

What's hot (20)

PPTX
C# classes objects
Dr.Neeraj Kumar Pandey
 
PPTX
Java abstract class & abstract methods
Shubham Dwivedi
 
PDF
Constructors and Destructors
Dr Sukhpal Singh Gill
 
PPT
16 virtual function
Docent Education
 
PPT
Class and object in C++
rprajat007
 
PDF
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Tushar B Kute
 
PPTX
Static Data Members and Member Functions
MOHIT AGARWAL
 
PPT
7.data types in c#
Zeeshan Ahmad
 
PPT
Java interfaces
Raja Sekhar
 
PPTX
Array of objects.pptx
RAGAVIC2
 
PPTX
Inner classes in java
PhD Research Scholar
 
PPTX
Object Oriented Programming with C#
foreverredpb
 
PPTX
Classes, objects in JAVA
Abhilash Nair
 
PPTX
Operator overloading
Ramish Suleman
 
PPTX
Abstract class and Interface
Haris Bin Zahid
 
PPTX
interface in c#
Deepti Pillai
 
PPTX
Dynamic method dispatch
yugandhar vadlamudi
 
PPS
Jdbc architecture and driver types ppt
kamal kotecha
 
PPTX
Static Members-Java.pptx
ADDAGIRIVENKATARAVIC
 
PPTX
Virtual base class
Tech_MX
 
C# classes objects
Dr.Neeraj Kumar Pandey
 
Java abstract class & abstract methods
Shubham Dwivedi
 
Constructors and Destructors
Dr Sukhpal Singh Gill
 
16 virtual function
Docent Education
 
Class and object in C++
rprajat007
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Tushar B Kute
 
Static Data Members and Member Functions
MOHIT AGARWAL
 
7.data types in c#
Zeeshan Ahmad
 
Java interfaces
Raja Sekhar
 
Array of objects.pptx
RAGAVIC2
 
Inner classes in java
PhD Research Scholar
 
Object Oriented Programming with C#
foreverredpb
 
Classes, objects in JAVA
Abhilash Nair
 
Operator overloading
Ramish Suleman
 
Abstract class and Interface
Haris Bin Zahid
 
interface in c#
Deepti Pillai
 
Dynamic method dispatch
yugandhar vadlamudi
 
Jdbc architecture and driver types ppt
kamal kotecha
 
Static Members-Java.pptx
ADDAGIRIVENKATARAVIC
 
Virtual base class
Tech_MX
 

Similar to Classes and Objects in C# (20)

PPTX
class c++
vinay chauhan
 
PDF
C++ Notes
MOHAMED RIYAZUDEEN
 
PPTX
OOPs & C++ UNIT 3
Dr. SURBHI SAROHA
 
PDF
Object Oriented Programming - 5. Class & Object
AndiNurkholis1
 
PDF
Class and object in C++ By Pawan Thakur
Govt. P.G. College Dharamshala
 
PPT
creating objects and Class methods
NainaKhan28
 
PPT
Class methods
NainaKhan29
 
PPTX
Class and object
prabhat kumar
 
PPTX
My Object Oriented.pptx
GopalNarayan7
 
PPT
Classes & objects new
lykado0dles
 
PPTX
Jscript part2
Girish Srivastava
 
PPTX
UNIT - IIInew.pptx
akila m
 
PPTX
Lecture 4.2 c++(comlete reference book)
Abu Saleh
 
PPT
object oriented programming language by c++
Mohamad Al_hsan
 
PPT
Object and class presentation
nafisa rahman
 
PPTX
basic concepts of object oriented programming
infotechsaasc
 
PPT
packages and interfaces
madhavi patil
 
PPTX
python.pptx
Dhanushrajucm
 
PPTX
C++ Presen. tation.pptx
mohitsinha7739289047
 
PPTX
Lecture 2, c++(complete reference,herbet sheidt)chapter-12
Abu Saleh
 
class c++
vinay chauhan
 
OOPs & C++ UNIT 3
Dr. SURBHI SAROHA
 
Object Oriented Programming - 5. Class & Object
AndiNurkholis1
 
Class and object in C++ By Pawan Thakur
Govt. P.G. College Dharamshala
 
creating objects and Class methods
NainaKhan28
 
Class methods
NainaKhan29
 
Class and object
prabhat kumar
 
My Object Oriented.pptx
GopalNarayan7
 
Classes & objects new
lykado0dles
 
Jscript part2
Girish Srivastava
 
UNIT - IIInew.pptx
akila m
 
Lecture 4.2 c++(comlete reference book)
Abu Saleh
 
object oriented programming language by c++
Mohamad Al_hsan
 
Object and class presentation
nafisa rahman
 
basic concepts of object oriented programming
infotechsaasc
 
packages and interfaces
madhavi patil
 
python.pptx
Dhanushrajucm
 
C++ Presen. tation.pptx
mohitsinha7739289047
 
Lecture 2, c++(complete reference,herbet sheidt)chapter-12
Abu Saleh
 
Ad

More from Adeel Rasheed (20)

PPTX
Multan to Sukkur Motorway (M5)
Adeel Rasheed
 
PPTX
Religious Conflict
Adeel Rasheed
 
DOCX
R Studio (Report)
Adeel Rasheed
 
DOCX
History of computer (1st to 5th Generations)
Adeel Rasheed
 
PPTX
CSS Cascade Style Sheet
Adeel Rasheed
 
PPTX
Zooming and Its Types
Adeel Rasheed
 
PPTX
User Interface & Its Types
Adeel Rasheed
 
DOCX
Questions About Android Application Development
Adeel Rasheed
 
PPTX
Human and Machine Learning
Adeel Rasheed
 
PPTX
Connection Establishment & Flow and Congestion Control
Adeel Rasheed
 
PPTX
IP Address - IPv4 & IPv6
Adeel Rasheed
 
PPTX
Computer Crime
Adeel Rasheed
 
PPTX
Privacy and Security Information
Adeel Rasheed
 
PPTX
Code of Conduct - Code of Practice & Standards
Adeel Rasheed
 
PPTX
Self Adaptive Systems
Adeel Rasheed
 
PPTX
Ethernet - LAN
Adeel Rasheed
 
PPTX
Synchronous and Asynchronous Transmission
Adeel Rasheed
 
DOCX
Intel Microprocessors 8086 Documentation
Adeel Rasheed
 
DOCX
Applications of Computer
Adeel Rasheed
 
DOCX
Hysteresis Loop
Adeel Rasheed
 
Multan to Sukkur Motorway (M5)
Adeel Rasheed
 
Religious Conflict
Adeel Rasheed
 
R Studio (Report)
Adeel Rasheed
 
History of computer (1st to 5th Generations)
Adeel Rasheed
 
CSS Cascade Style Sheet
Adeel Rasheed
 
Zooming and Its Types
Adeel Rasheed
 
User Interface & Its Types
Adeel Rasheed
 
Questions About Android Application Development
Adeel Rasheed
 
Human and Machine Learning
Adeel Rasheed
 
Connection Establishment & Flow and Congestion Control
Adeel Rasheed
 
IP Address - IPv4 & IPv6
Adeel Rasheed
 
Computer Crime
Adeel Rasheed
 
Privacy and Security Information
Adeel Rasheed
 
Code of Conduct - Code of Practice & Standards
Adeel Rasheed
 
Self Adaptive Systems
Adeel Rasheed
 
Ethernet - LAN
Adeel Rasheed
 
Synchronous and Asynchronous Transmission
Adeel Rasheed
 
Intel Microprocessors 8086 Documentation
Adeel Rasheed
 
Applications of Computer
Adeel Rasheed
 
Hysteresis Loop
Adeel Rasheed
 
Ad

Recently uploaded (20)

PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 

Classes and Objects in C#

  • 3.  A class is a construct that enables you to create your own custom types by grouping together variables of other types, methods and events.  It defines the data and behavior of a type.  Supports the OOP principle "encapsulation“  Fields and methods can be:: Instance (or object members) Static (or class members)
  • 4. Class definition consists of  Class declaration  Data Fields  Constructors  Properties  Methods class test{ public int a = 5, b = 10; public void mul(){ Console.Write("The Result of Multiply is = {0}", a * b); Console.ReadLine(); }}
  • 5. Classes Classes are declared by using the keyword class followed by the class name and a set of class members surrounded by curly braces { }. class House { Body ... }
  • 6. Basic syntax for class declaration Class comprises a class header and class body. class class_name { class body } Note: No semicolon (;) to terminate class block. But statements must be terminated with a semicolon ;
  • 7.  In C#, individual classes and class members need to be prefixed with visibility modifiers.  By default, if you declare a member variable (or anything else) in a class but do not specify its access level, the member is considered private and cannot be accessed from outside, i.e. by a non-member of that class.  Therefore, to make a member accessible by other classes, you must declare it as public.
  • 8.  Object is an abstraction of real world entity.  Syntax for declaring objects is as follows :  MyClass objMyClass = new MyClass();
  • 9.  It can have its own copy of data members.  It can be passed to a function like normal variables.  The members of the class can accessed by the object using the object to member access operator or dot operator(.).
  • 10.  Create Object  Call function and variables with the help of object  MyClass objMyClass = new MyClass();  objMycClass.function_name();  objMycClass.variable;
  • 11. Constructors public MyClass(parameters) {...} • new operator – create an instance of the class MyClass objMyClass = new MyClass(); public Person() { name = null; age = 0; }
  • 12.  class testt{  public static int a = 5, b = 10;  public static void mul(){  Console.Write("The Result of Multiply is = {0}", a * b);  Console.ReadLine();  }}
  • 13.  MyClass objMyClass1 = new MyClass();  objMycClass1.function_name();  MyClass objMyClass2 = new MyClass();  objMycClass2.function_name();  MyClass.function_name();