SlideShare a Scribd company logo
1 of 23
What Is an Indexer?
• An indexer is a set of get and set accessors,
  similar to those of properties
Indexers and Properties
Indexers and properties are similar in many ways.
• • Like a property, an indexer does not allocate
  memory for storage.
• • Both indexers and properties are used primarily
  for giving access to other data members with
  which they are associated, and for which they
  provide set and get access.
  – – A property is usually accessing a single data
    member.
  – – An indexer is usually accessing multiple data
    members.
Some additional points
• • An indexer can have either one or both of the
  accessors.
• • Indexers are always instance members; hence,
  an indexer cannot be declared static.
• • Like properties, the code implementing the get
  and set accessors does not have to be
• associated with any fields or properties. The code
  can do anything, or nothing, as long as the get
  accessor returns some value of the specified
  type.
Declaring an Indexer
• • An indexer does not have a name. In place of
  the name is the keyword this.
• • The parameter list is between square
  brackets.
• • There must be at least one parameter
  declaration in the parameter list.
Declaring an Indexer
Comparing an indexer declaration to a
       property declaration
The set Accessor
When the indexer is the target of an assignment,
 the set accessor is called, and receives two
 items of data.
  – • An implicit parameter, named value, where
    value holds the data to be stored.
  – • One or more index parameters that represent
    where it should be stored.
The get Accessor
• When the indexer is used to retrieve a value,
  the get accessor is called with one or more
  index parameters.
• The code in the get accessor body must
  examine the index parameters, determine
  which field they represent, and return the
  value of that field.
• • It has the same parameter list as in the
  indexer declaration.
• • It returns a value of the same type as the
  indexer.
More About Indexers
As with properties, the get and set accessors
  cannot be called explicitly. Instead, the get
  accessor is called automatically when the
  indexer is used in an expression for a value.
  The set accessor is called automatically when
  the indexer is assigned a value with the
  assignment statement.
•   class Class1                                 •   Temp1 = value; // Note the implicit
•   {                                                variable "value".
•   int Temp0; // Private field                  •   }
•   int Temp1; // Private field                  •   }
•   public int this [ int index ] // The indexer •   }
•   {                                            •   class Example
•   get                                          •   {
•   {                                            •   static void Main()
•   return ( 0 == index ) // Return value of •       {
    either Temp0 or Temp1                        •   Class1 a = new Class1();
•   ? Temp0                                      •   Console.WriteLine("Values -- T0: {0}, T1:
•   : Temp1;                                         {1}", a[0], a[1]);
•   }                                            •   a[0] = 15;
•   set                                          •   a[1] = 20;
•   {                                            •   Console.WriteLine("Values -- T0: {0}, T1:
•   if( 0 == index )                                 {1}", a[0], a[1]);
•   Temp0 = value; // Note the implicit          •   }
    variable "value".                            •   }
•   else
Access Modifiers on Accessors
There are several restrictions on the access
  modifiers of accessors.
  – • An accessor can have an access modifier only if
    the member (property or indexer) has both a get
    accessor and a set accessor.
  – • Although both accessors must be present, only
    one of them can have an access modifier.
  – • The access modifier of the accessor must be
    strictly more restrictive than the access level of the
    member.
Hierarchy of strictly restrictive accessor
                  levels
Indexer Overloading
•   class MyClass
•   {
•   public string this [ int index ]
•   {
•   get { ... }
•   set { ... }
•   }
•   public string this [ int index1, int index2 ]
•   {
•   get { ... }
•   set { ... }
•   }
•   public int this [ float index1 ]
•   {
•   get { ... }
•   set { ... }
•   }
•   ...
•   }
Partial Classes and Partial Types
Partial Class
• The declaration of a class can be partitioned
  among several partial class declarations.
  – • Each of the partial class declarations contains
    the declarations of some of the class members.
  – • The partial class declarations of a class can be in
    the same file or in different files.
•   Type modifier
•   partial class MyPartClass // Same class name as following
•   {
•   member1 declaration
•   member2 declaration
•   ...
•   }
•   Type modifier
•   partial class MyPartClass // Same class name as preceding
•   {
•   member3 declaration
•   member4 declaration
•   ...
•   }
• All the partial class declarations comprising a
  class must be compiled together.
• A class using partial class declarations has the
  same meaning as if all the class members
  were declared within a single class declaration
  body.
• Besides classes, you can also create two other
  partial types:
  – • Partial structs.
  – • Partial interfaces.
Partial Methods
• Partial methods are methods that are declared in
  two parts in a partial class.
• The two parts of the partial method are:
  – • The defining partial method declaration gives the
    signature and return type, and the implementation
    part of the declaration consists of only a semicolon.
  – • The implementing partial method declaration gives
    the signature, return type, and also the
    implementation in the normal format of a statement
    block.
The important things to know
• • Both the defining and implementing declaration must
  match in signature and return type. The signature and
  return type have the following characteristics:
   – – The contextual keyword partial must be included in both the
     defining and implementing declarations immediately before the
     keyword void.
   – – The signature cannot include access modifiers⎯making partial
     methods implicitly private.
   – – The return type must be void.
   – – The parameter list cannot contain out parameters.
• • You can have a defining partial method without an
  implementing partial method. In this case, the compiler
  removes the declaration and any calls to the method made
  inside the class. If, however, the class has an implementing
  partial method, it must also have a defining partial method.
Indexers, Partial Class And Partial Method

More Related Content

What's hot

What's hot (14)

CSharp for Unity Day 3
CSharp for Unity Day 3CSharp for Unity Day 3
CSharp for Unity Day 3
 
Variable
VariableVariable
Variable
 
Unit3 part3-packages and interfaces
Unit3 part3-packages and interfacesUnit3 part3-packages and interfaces
Unit3 part3-packages and interfaces
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
Java Tutorial Lab 1
Java Tutorial Lab 1Java Tutorial Lab 1
Java Tutorial Lab 1
 
Adobe Flash Actionscript language basics chapter-2
Adobe Flash Actionscript language basics chapter-2Adobe Flash Actionscript language basics chapter-2
Adobe Flash Actionscript language basics chapter-2
 
Java static keyword
Java static keywordJava static keyword
Java static keyword
 
Unit 5 java-awt (1)
Unit 5 java-awt (1)Unit 5 java-awt (1)
Unit 5 java-awt (1)
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
 
6. static keyword
6. static keyword6. static keyword
6. static keyword
 
Packages and interfaces
Packages and interfacesPackages and interfaces
Packages and interfaces
 
Cis166 Final Review C#
Cis166 Final Review C#Cis166 Final Review C#
Cis166 Final Review C#
 
Smoke and Mirrors - Reflection in C#
Smoke and Mirrors - Reflection in C#Smoke and Mirrors - Reflection in C#
Smoke and Mirrors - Reflection in C#
 
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysUnit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
 

Viewers also liked

Csharp In Detail Part2
Csharp In Detail Part2Csharp In Detail Part2
Csharp In Detail Part2
Mohamed Krar
 
Toledo Harbor Dredging Summit 2009
Toledo Harbor Dredging Summit 2009Toledo Harbor Dredging Summit 2009
Toledo Harbor Dredging Summit 2009
HKemler
 
태국을 여행하자!!
태국을 여행하자!!태국을 여행하자!!
태국을 여행하자!!
guestb0502dd0
 
Ratings made simple edited
Ratings made simple editedRatings made simple edited
Ratings made simple edited
mediaplaylab
 
Teaching disgrace using Second Life
Teaching disgrace using Second LifeTeaching disgrace using Second Life
Teaching disgrace using Second Life
mediaplaylab
 
Diacritice romanesti in ym 2
Diacritice romanesti in ym 2Diacritice romanesti in ym 2
Diacritice romanesti in ym 2
dianaifrim
 
Looppa value proposition
Looppa value propositionLooppa value proposition
Looppa value proposition
Looppa
 
Performance of investment funds berhmani frigerio pan
Performance of investment funds berhmani frigerio panPerformance of investment funds berhmani frigerio pan
Performance of investment funds berhmani frigerio pan
BERHMANI Samuel
 
Exposure Lecture 2014 - Tamil Language
Exposure Lecture 2014 - Tamil LanguageExposure Lecture 2014 - Tamil Language
Exposure Lecture 2014 - Tamil Language
mediaplaylab
 
IRL FTW! Organizing Meetups and WordCamps
IRL FTW! Organizing Meetups and WordCampsIRL FTW! Organizing Meetups and WordCamps
IRL FTW! Organizing Meetups and WordCamps
Aaron Hockley
 
Presentation1 1 1
Presentation1 1 1Presentation1 1 1
Presentation1 1 1
3246
 
презентация1
презентация1презентация1
презентация1
guest08adc2
 
Video Paper Builder
Video Paper BuilderVideo Paper Builder
Video Paper Builder
mediaplaylab
 

Viewers also liked (20)

Csharp In Detail Part2
Csharp In Detail Part2Csharp In Detail Part2
Csharp In Detail Part2
 
Indexes in orthodontics
Indexes in orthodonticsIndexes in orthodontics
Indexes in orthodontics
 
C# Generics
C# GenericsC# Generics
C# Generics
 
Indices
IndicesIndices
Indices
 
Toledo Harbor Dredging Summit 2009
Toledo Harbor Dredging Summit 2009Toledo Harbor Dredging Summit 2009
Toledo Harbor Dredging Summit 2009
 
태국을 여행하자!!
태국을 여행하자!!태국을 여행하자!!
태국을 여행하자!!
 
Ratings made simple edited
Ratings made simple editedRatings made simple edited
Ratings made simple edited
 
Mobile apps - Justfone
Mobile apps - JustfoneMobile apps - Justfone
Mobile apps - Justfone
 
Teaching disgrace using Second Life
Teaching disgrace using Second LifeTeaching disgrace using Second Life
Teaching disgrace using Second Life
 
Introduction to Service Design for Translink
Introduction to Service Design for TranslinkIntroduction to Service Design for Translink
Introduction to Service Design for Translink
 
Diacritice romanesti in ym 2
Diacritice romanesti in ym 2Diacritice romanesti in ym 2
Diacritice romanesti in ym 2
 
Looppa value proposition
Looppa value propositionLooppa value proposition
Looppa value proposition
 
Performance of investment funds berhmani frigerio pan
Performance of investment funds berhmani frigerio panPerformance of investment funds berhmani frigerio pan
Performance of investment funds berhmani frigerio pan
 
Exposure Lecture 2014 - Tamil Language
Exposure Lecture 2014 - Tamil LanguageExposure Lecture 2014 - Tamil Language
Exposure Lecture 2014 - Tamil Language
 
IRL FTW! Organizing Meetups and WordCamps
IRL FTW! Organizing Meetups and WordCampsIRL FTW! Organizing Meetups and WordCamps
IRL FTW! Organizing Meetups and WordCamps
 
Presentation1 1 1
Presentation1 1 1Presentation1 1 1
Presentation1 1 1
 
презентация1
презентация1презентация1
презентация1
 
England
EnglandEngland
England
 
A Look at the Rainmaker Platform
A Look at the Rainmaker PlatformA Look at the Rainmaker Platform
A Look at the Rainmaker Platform
 
Video Paper Builder
Video Paper BuilderVideo Paper Builder
Video Paper Builder
 

Similar to Indexers, Partial Class And Partial Method

Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
Edureka!
 

Similar to Indexers, Partial Class And Partial Method (20)

Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Object oriented programming in C++
Object oriented programming in C++Object oriented programming in C++
Object oriented programming in C++
 
class and object C++ language chapter 2.pptx
class and object C++ language chapter 2.pptxclass and object C++ language chapter 2.pptx
class and object C++ language chapter 2.pptx
 
Constructors and Method Overloading
Constructors and Method OverloadingConstructors and Method Overloading
Constructors and Method Overloading
 
C++ - Constructors,Destructors, Operator overloading and Type conversion
C++ - Constructors,Destructors, Operator overloading and Type conversionC++ - Constructors,Destructors, Operator overloading and Type conversion
C++ - Constructors,Destructors, Operator overloading and Type conversion
 
2 BytesC++ course_2014_c6_ constructors and other tools
2 BytesC++ course_2014_c6_ constructors and other tools2 BytesC++ course_2014_c6_ constructors and other tools
2 BytesC++ course_2014_c6_ constructors and other tools
 
java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming Needs
 
First Class Variables as AST Annotations
 First Class Variables as AST Annotations First Class Variables as AST Annotations
First Class Variables as AST Annotations
 
First Class Variables as AST Annotations
First Class Variables as AST AnnotationsFirst Class Variables as AST Annotations
First Class Variables as AST Annotations
 
static MEMBER IN OOPS PROGRAMING LANGUAGE.pptx
static MEMBER IN OOPS PROGRAMING LANGUAGE.pptxstatic MEMBER IN OOPS PROGRAMING LANGUAGE.pptx
static MEMBER IN OOPS PROGRAMING LANGUAGE.pptx
 
static members in object oriented program.pptx
static members in object oriented program.pptxstatic members in object oriented program.pptx
static members in object oriented program.pptx
 
Functions, classes & objects in c++
Functions, classes & objects in c++Functions, classes & objects in c++
Functions, classes & objects in c++
 
C++ training
C++ training C++ training
C++ training
 
Functions
FunctionsFunctions
Functions
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
 
5variables in c#
5variables in c#5variables in c#
5variables in c#
 
STORAGE CLASS.pptx
STORAGE CLASS.pptxSTORAGE CLASS.pptx
STORAGE CLASS.pptx
 
30csharp
30csharp30csharp
30csharp
 
30c
30c30c
30c
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

Indexers, Partial Class And Partial Method

  • 1. What Is an Indexer?
  • 2. • An indexer is a set of get and set accessors, similar to those of properties
  • 3. Indexers and Properties Indexers and properties are similar in many ways. • • Like a property, an indexer does not allocate memory for storage. • • Both indexers and properties are used primarily for giving access to other data members with which they are associated, and for which they provide set and get access. – – A property is usually accessing a single data member. – – An indexer is usually accessing multiple data members.
  • 4. Some additional points • • An indexer can have either one or both of the accessors. • • Indexers are always instance members; hence, an indexer cannot be declared static. • • Like properties, the code implementing the get and set accessors does not have to be • associated with any fields or properties. The code can do anything, or nothing, as long as the get accessor returns some value of the specified type.
  • 5. Declaring an Indexer • • An indexer does not have a name. In place of the name is the keyword this. • • The parameter list is between square brackets. • • There must be at least one parameter declaration in the parameter list.
  • 7. Comparing an indexer declaration to a property declaration
  • 8. The set Accessor When the indexer is the target of an assignment, the set accessor is called, and receives two items of data. – • An implicit parameter, named value, where value holds the data to be stored. – • One or more index parameters that represent where it should be stored.
  • 9. The get Accessor • When the indexer is used to retrieve a value, the get accessor is called with one or more index parameters. • The code in the get accessor body must examine the index parameters, determine which field they represent, and return the value of that field.
  • 10. • • It has the same parameter list as in the indexer declaration. • • It returns a value of the same type as the indexer.
  • 11. More About Indexers As with properties, the get and set accessors cannot be called explicitly. Instead, the get accessor is called automatically when the indexer is used in an expression for a value. The set accessor is called automatically when the indexer is assigned a value with the assignment statement.
  • 12.
  • 13. class Class1 • Temp1 = value; // Note the implicit • { variable "value". • int Temp0; // Private field • } • int Temp1; // Private field • } • public int this [ int index ] // The indexer • } • { • class Example • get • { • { • static void Main() • return ( 0 == index ) // Return value of • { either Temp0 or Temp1 • Class1 a = new Class1(); • ? Temp0 • Console.WriteLine("Values -- T0: {0}, T1: • : Temp1; {1}", a[0], a[1]); • } • a[0] = 15; • set • a[1] = 20; • { • Console.WriteLine("Values -- T0: {0}, T1: • if( 0 == index ) {1}", a[0], a[1]); • Temp0 = value; // Note the implicit • } variable "value". • } • else
  • 14. Access Modifiers on Accessors There are several restrictions on the access modifiers of accessors. – • An accessor can have an access modifier only if the member (property or indexer) has both a get accessor and a set accessor. – • Although both accessors must be present, only one of them can have an access modifier. – • The access modifier of the accessor must be strictly more restrictive than the access level of the member.
  • 15. Hierarchy of strictly restrictive accessor levels
  • 16. Indexer Overloading • class MyClass • { • public string this [ int index ] • { • get { ... } • set { ... } • } • public string this [ int index1, int index2 ] • { • get { ... } • set { ... } • } • public int this [ float index1 ] • { • get { ... } • set { ... } • } • ... • }
  • 17. Partial Classes and Partial Types
  • 18. Partial Class • The declaration of a class can be partitioned among several partial class declarations. – • Each of the partial class declarations contains the declarations of some of the class members. – • The partial class declarations of a class can be in the same file or in different files.
  • 19. Type modifier • partial class MyPartClass // Same class name as following • { • member1 declaration • member2 declaration • ... • } • Type modifier • partial class MyPartClass // Same class name as preceding • { • member3 declaration • member4 declaration • ... • }
  • 20. • All the partial class declarations comprising a class must be compiled together. • A class using partial class declarations has the same meaning as if all the class members were declared within a single class declaration body. • Besides classes, you can also create two other partial types: – • Partial structs. – • Partial interfaces.
  • 21. Partial Methods • Partial methods are methods that are declared in two parts in a partial class. • The two parts of the partial method are: – • The defining partial method declaration gives the signature and return type, and the implementation part of the declaration consists of only a semicolon. – • The implementing partial method declaration gives the signature, return type, and also the implementation in the normal format of a statement block.
  • 22. The important things to know • • Both the defining and implementing declaration must match in signature and return type. The signature and return type have the following characteristics: – – The contextual keyword partial must be included in both the defining and implementing declarations immediately before the keyword void. – – The signature cannot include access modifiers⎯making partial methods implicitly private. – – The return type must be void. – – The parameter list cannot contain out parameters. • • You can have a defining partial method without an implementing partial method. In this case, the compiler removes the declaration and any calls to the method made inside the class. If, however, the class has an implementing partial method, it must also have a defining partial method.