SlideShare a Scribd company logo
 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

Java IO
Java IOJava IO
Java IO
UTSAB NEUPANE
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#Doncho Minkov
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
Madishetty Prathibha
 
Methods in C#
Methods in C#Methods in C#
Methods in C#
Prasanna Kumar SM
 
Object oriented programming With C#
Object oriented programming With C#Object oriented programming With C#
Object oriented programming With C#
Youssef Mohammed Abohaty
 
C# program structure
C# program structureC# program structure
Ppt on this and super keyword
Ppt on this and super keywordPpt on this and super keyword
Ppt on this and super keyword
tanu_jaswal
 
Program control statements in c#
Program control statements in c#Program control statements in c#
Program control statements in c#
Dr.Neeraj Kumar Pandey
 
Java Tokens
Java  TokensJava  Tokens
Files in java
Files in javaFiles in java
Types of methods in python
Types of methods in pythonTypes of methods in python
Types of methods in python
Aravindreddy Mokireddy
 
C# operators
C# operatorsC# operators
Java Annotations
Java AnnotationsJava Annotations
Java Annotations
Serhii Kartashov
 
C# Access modifiers
C# Access modifiersC# Access modifiers
C# Access modifiers
Prem Kumar Badri
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
Hitesh Kumar
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloading
Shivam Singhal
 
Abstract class
Abstract classAbstract class
Abstract class
Tony Nguyen
 

What's hot (20)

Java IO
Java IOJava IO
Java IO
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
 
Methods in C#
Methods in C#Methods in C#
Methods in C#
 
interface in c#
interface in c#interface in c#
interface in c#
 
Object oriented programming With C#
Object oriented programming With C#Object oriented programming With C#
Object oriented programming With C#
 
C# program structure
C# program structureC# program structure
C# program structure
 
Ppt on this and super keyword
Ppt on this and super keywordPpt on this and super keyword
Ppt on this and super keyword
 
Oops concept on c#
Oops concept on c#Oops concept on c#
Oops concept on c#
 
Program control statements in c#
Program control statements in c#Program control statements in c#
Program control statements in c#
 
C# Delegates
C# DelegatesC# Delegates
C# Delegates
 
Java Tokens
Java  TokensJava  Tokens
Java Tokens
 
Files in java
Files in javaFiles in java
Files in java
 
Types of methods in python
Types of methods in pythonTypes of methods in python
Types of methods in python
 
C# operators
C# operatorsC# operators
C# operators
 
Java Annotations
Java AnnotationsJava Annotations
Java Annotations
 
C# Access modifiers
C# Access modifiersC# Access modifiers
C# Access modifiers
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloading
 
Abstract class
Abstract classAbstract class
Abstract class
 

Similar to Classes and Objects in C#

class c++
class c++class c++
class c++
vinay chauhan
 
C++ Notes
C++ NotesC++ Notes
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#
foreverredpb
 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3
SURBHI SAROHA
 
Object Oriented Programming - 5. Class & Object
Object Oriented Programming - 5. Class & ObjectObject Oriented Programming - 5. Class & Object
Object Oriented Programming - 5. Class & Object
AndiNurkholis1
 
Class and object in C++ By Pawan Thakur
Class and object in C++ By Pawan ThakurClass and object in C++ By Pawan Thakur
Class and object in C++ By Pawan Thakur
Govt. P.G. College Dharamshala
 
Class methods
Class methodsClass methods
Class methods
NainaKhan29
 
creating objects and Class methods
creating objects and Class methodscreating objects and Class methods
creating objects and Class methods
NainaKhan28
 
Class and object
Class and objectClass and object
Class and object
prabhat kumar
 
My Object Oriented.pptx
My Object Oriented.pptxMy Object Oriented.pptx
My Object Oriented.pptx
GopalNarayan7
 
Classes & objects new
Classes & objects newClasses & objects new
Classes & objects newlykado0dles
 
UNIT - IIInew.pptx
UNIT - IIInew.pptxUNIT - IIInew.pptx
UNIT - IIInew.pptx
akila m
 
Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)
Abu Saleh
 
object oriented programming language by c++
object oriented programming language by c++object oriented programming language by c++
object oriented programming language by c++
Mohamad Al_hsan
 
Object and class presentation
Object and class presentationObject and class presentation
Object and class presentation
nafisa rahman
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfaces
madhavi patil
 
python.pptx
python.pptxpython.pptx
python.pptx
Dhanushrajucm
 
Lecture 2, c++(complete reference,herbet sheidt)chapter-12
Lecture 2, c++(complete reference,herbet sheidt)chapter-12Lecture 2, c++(complete reference,herbet sheidt)chapter-12
Lecture 2, c++(complete reference,herbet sheidt)chapter-12
Abu Saleh
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
ssuser8347a1
 

Similar to Classes and Objects in C# (20)

class c++
class c++class c++
class c++
 
C++ Notes
C++ NotesC++ Notes
C++ Notes
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#
 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3
 
Object Oriented Programming - 5. Class & Object
Object Oriented Programming - 5. Class & ObjectObject Oriented Programming - 5. Class & Object
Object Oriented Programming - 5. Class & Object
 
Class and object in C++ By Pawan Thakur
Class and object in C++ By Pawan ThakurClass and object in C++ By Pawan Thakur
Class and object in C++ By Pawan Thakur
 
Class methods
Class methodsClass methods
Class methods
 
creating objects and Class methods
creating objects and Class methodscreating objects and Class methods
creating objects and Class methods
 
Class and object
Class and objectClass and object
Class and object
 
My Object Oriented.pptx
My Object Oriented.pptxMy Object Oriented.pptx
My Object Oriented.pptx
 
Classes & objects new
Classes & objects newClasses & objects new
Classes & objects new
 
Jscript part2
Jscript part2Jscript part2
Jscript part2
 
UNIT - IIInew.pptx
UNIT - IIInew.pptxUNIT - IIInew.pptx
UNIT - IIInew.pptx
 
Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)
 
object oriented programming language by c++
object oriented programming language by c++object oriented programming language by c++
object oriented programming language by c++
 
Object and class presentation
Object and class presentationObject and class presentation
Object and class presentation
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfaces
 
python.pptx
python.pptxpython.pptx
python.pptx
 
Lecture 2, c++(complete reference,herbet sheidt)chapter-12
Lecture 2, c++(complete reference,herbet sheidt)chapter-12Lecture 2, c++(complete reference,herbet sheidt)chapter-12
Lecture 2, c++(complete reference,herbet sheidt)chapter-12
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
 

More from Adeel Rasheed

Multan to Sukkur Motorway (M5)
Multan to Sukkur Motorway (M5)Multan to Sukkur Motorway (M5)
Multan to Sukkur Motorway (M5)
Adeel Rasheed
 
Religious Conflict
Religious ConflictReligious Conflict
Religious Conflict
Adeel Rasheed
 
R Studio (Report)
R Studio (Report)R Studio (Report)
R Studio (Report)
Adeel Rasheed
 
History of computer (1st to 5th Generations)
History of computer (1st to 5th Generations)History of computer (1st to 5th Generations)
History of computer (1st to 5th Generations)
Adeel Rasheed
 
CSS Cascade Style Sheet
CSS Cascade Style SheetCSS Cascade Style Sheet
CSS Cascade Style Sheet
Adeel Rasheed
 
Zooming and Its Types
Zooming and Its TypesZooming and Its Types
Zooming and Its Types
Adeel Rasheed
 
User Interface & Its Types
User Interface & Its TypesUser Interface & Its Types
User Interface & Its Types
Adeel Rasheed
 
Questions About Android Application Development
Questions About Android Application DevelopmentQuestions About Android Application Development
Questions About Android Application Development
Adeel Rasheed
 
Human and Machine Learning
Human and Machine LearningHuman and Machine Learning
Human and Machine Learning
Adeel Rasheed
 
Connection Establishment & Flow and Congestion Control
Connection Establishment & Flow and Congestion ControlConnection Establishment & Flow and Congestion Control
Connection Establishment & Flow and Congestion Control
Adeel Rasheed
 
IP Address - IPv4 & IPv6
IP Address - IPv4 & IPv6IP Address - IPv4 & IPv6
IP Address - IPv4 & IPv6
Adeel Rasheed
 
Computer Crime
Computer CrimeComputer Crime
Computer Crime
Adeel Rasheed
 
Privacy and Security Information
Privacy and Security InformationPrivacy and Security Information
Privacy and Security Information
Adeel Rasheed
 
Code of Conduct - Code of Practice & Standards
Code of Conduct - Code of Practice & StandardsCode of Conduct - Code of Practice & Standards
Code of Conduct - Code of Practice & Standards
Adeel Rasheed
 
Self Adaptive Systems
Self Adaptive SystemsSelf Adaptive Systems
Self Adaptive Systems
Adeel Rasheed
 
Ethernet - LAN
Ethernet - LANEthernet - LAN
Ethernet - LAN
Adeel Rasheed
 
Synchronous and Asynchronous Transmission
Synchronous and Asynchronous TransmissionSynchronous and Asynchronous Transmission
Synchronous and Asynchronous Transmission
Adeel Rasheed
 
Intel Microprocessors 8086 Documentation
Intel Microprocessors 8086 DocumentationIntel Microprocessors 8086 Documentation
Intel Microprocessors 8086 Documentation
Adeel Rasheed
 
Applications of Computer
Applications of ComputerApplications of Computer
Applications of Computer
Adeel Rasheed
 
Hysteresis Loop
Hysteresis LoopHysteresis Loop
Hysteresis Loop
Adeel Rasheed
 

More from Adeel Rasheed (20)

Multan to Sukkur Motorway (M5)
Multan to Sukkur Motorway (M5)Multan to Sukkur Motorway (M5)
Multan to Sukkur Motorway (M5)
 
Religious Conflict
Religious ConflictReligious Conflict
Religious Conflict
 
R Studio (Report)
R Studio (Report)R Studio (Report)
R Studio (Report)
 
History of computer (1st to 5th Generations)
History of computer (1st to 5th Generations)History of computer (1st to 5th Generations)
History of computer (1st to 5th Generations)
 
CSS Cascade Style Sheet
CSS Cascade Style SheetCSS Cascade Style Sheet
CSS Cascade Style Sheet
 
Zooming and Its Types
Zooming and Its TypesZooming and Its Types
Zooming and Its Types
 
User Interface & Its Types
User Interface & Its TypesUser Interface & Its Types
User Interface & Its Types
 
Questions About Android Application Development
Questions About Android Application DevelopmentQuestions About Android Application Development
Questions About Android Application Development
 
Human and Machine Learning
Human and Machine LearningHuman and Machine Learning
Human and Machine Learning
 
Connection Establishment & Flow and Congestion Control
Connection Establishment & Flow and Congestion ControlConnection Establishment & Flow and Congestion Control
Connection Establishment & Flow and Congestion Control
 
IP Address - IPv4 & IPv6
IP Address - IPv4 & IPv6IP Address - IPv4 & IPv6
IP Address - IPv4 & IPv6
 
Computer Crime
Computer CrimeComputer Crime
Computer Crime
 
Privacy and Security Information
Privacy and Security InformationPrivacy and Security Information
Privacy and Security Information
 
Code of Conduct - Code of Practice & Standards
Code of Conduct - Code of Practice & StandardsCode of Conduct - Code of Practice & Standards
Code of Conduct - Code of Practice & Standards
 
Self Adaptive Systems
Self Adaptive SystemsSelf Adaptive Systems
Self Adaptive Systems
 
Ethernet - LAN
Ethernet - LANEthernet - LAN
Ethernet - LAN
 
Synchronous and Asynchronous Transmission
Synchronous and Asynchronous TransmissionSynchronous and Asynchronous Transmission
Synchronous and Asynchronous Transmission
 
Intel Microprocessors 8086 Documentation
Intel Microprocessors 8086 DocumentationIntel Microprocessors 8086 Documentation
Intel Microprocessors 8086 Documentation
 
Applications of Computer
Applications of ComputerApplications of Computer
Applications of Computer
 
Hysteresis Loop
Hysteresis LoopHysteresis Loop
Hysteresis Loop
 

Recently uploaded

Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 

Recently uploaded (20)

Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 

Classes and Objects in C#

  • 1.
  • 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();