SlideShare a Scribd company logo
1 of 10
ACTIVE LEARNING
ASSIGNMENT FOR THE
SUBJECT
“DOT NET”
PROPERTIES AND INDEXERS IN C#
Guided By : -
Nitin Patel
(Assistance prof.)
Prepared By :-
Hemant H. Chetwani
(130410107010 TY CE-II)
Contents
 Properties.
 Accessors.
 Example of property.
 Indexers.
 Use of indexers.
 Example of indexer.
 Difference of property & indexer.
PROPERTIES
• Properties are named members of classes, structures, and interfaces.
Member variables or methods in a class or structures are called Fields.
Properties are an extension of fields and are accessed using the same
syntax.They use accessors through which the values of the private
fields can be read, written, or manipulated.
• Properties do not name the storage locations. Instead, they have
accessors that read, write, or compute their values.
• For example, let us have a class named Student, with private fields
for age, name, and code.We cannot directly access these fields from
outside the class scope, but we can have properties for accessing
these private fields.
ACCESSORS
The accessor of a property contains the
executable statements that helps in getting
(reading or computing) or setting (writing) the
property. In short getter and setter methods
are known as accessors.
Property : Simple Example
public class Student
{
private string Name;
public string name
{
get
{
return name;
}
set
{
name = value;
}
}
}
Student s = new Student();
s.Name = “Hemant";
Console.WriteLine(s);
INDEXERS
An indexer allows an object to be indexed such as
an array.When you define an indexer for a class,
this class behaves similar to a virtual array.You
can then access the instance of this class using
the array access operator ([ ]).
USE OF INDEXERS
• Declaration of behavior of an indexer is to some extent similar to a
property. Similar to the properties, you use get and set accessors for
defining an indexer. However, properties return or set a specific data
member, whereas indexers returns or sets a particular value from the
object instance. In other words, it breaks the instance data into
smaller parts and indexes each part, gets or sets each part.
• Defining a property involves providing a property name. Indexers are
not defined with names, but with the this keyword, which refers to
the object instance.The following example demonstrates the
concept:
Indexer: Simple Example
public class ListBox
{
private string[] items;
public string this[int index]
{
get
{
return items[index];
}
set
{
items[index] = value;
}
}
}
ListBox listBox = new ListBox();
listBox[0] = "hello";
Console.WriteLine(listBox[0]);
Difference between Property & Indexer
Property Indexer
Allows methods to be called as if they were public
data members.
Allows elements of an internal collection of an
object to be accessed by using array notation on
the object itself.
Accessed through a simple name. Accessed through an index.
Can be a static or an instance member. Must be an instance member.
A get accessor of a property has no parameters. A get accessor of an indexer has the same formal
parameter list as the indexer.
A set accessor of a property contains the
implicit value parameter.
A set accessor of an indexer has the same formal
parameter list as the indexer, and also to the value
parameter.
DOT NET PROPERTIES AND INDEXERS

More Related Content

What's hot (20)

Java collections
Java collectionsJava collections
Java collections
 
Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection framework
 
Generics
GenericsGenerics
Generics
 
LINQ
LINQLINQ
LINQ
 
Web html table tags
Web html  table tagsWeb html  table tags
Web html table tags
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Inheritance C#
Inheritance C#Inheritance C#
Inheritance C#
 
Servlets
ServletsServlets
Servlets
 
JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and Functions
 
Java constructors
Java constructorsJava constructors
Java constructors
 
Packages in PL/SQL
Packages in PL/SQLPackages in PL/SQL
Packages in PL/SQL
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Methods in C#
Methods in C#Methods in C#
Methods in C#
 

Similar to DOT NET PROPERTIES AND INDEXERS (20)

CSharp for Unity Day 3
CSharp for Unity Day 3CSharp for Unity Day 3
CSharp for Unity Day 3
 
Oops
OopsOops
Oops
 
Indexers in C#
Indexers in C#Indexers in C#
Indexers in C#
 
Objects and Types C#
Objects and Types C#Objects and Types C#
Objects and Types C#
 
20csharp
20csharp20csharp
20csharp
 
20c
20c20c
20c
 
Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programming
 
Properties and Indexers
Properties and IndexersProperties and Indexers
Properties and Indexers
 
Structure in c language
Structure in c languageStructure in c language
Structure in c language
 
Linq
LinqLinq
Linq
 
Linq
LinqLinq
Linq
 
Unit ii
Unit   iiUnit   ii
Unit ii
 
Unit 2-Data Modeling.pdf
Unit 2-Data Modeling.pdfUnit 2-Data Modeling.pdf
Unit 2-Data Modeling.pdf
 
C++ training
C++ training C++ training
C++ training
 
Structures
StructuresStructures
Structures
 
OOAD.pptx
OOAD.pptxOOAD.pptx
OOAD.pptx
 
Understanding-Objects-in-Javascript.pptx
Understanding-Objects-in-Javascript.pptxUnderstanding-Objects-in-Javascript.pptx
Understanding-Objects-in-Javascript.pptx
 
Linq in C# 3.0: An Overview
Linq in C# 3.0: An OverviewLinq in C# 3.0: An Overview
Linq in C# 3.0: An Overview
 
C# program structure
C# program structureC# program structure
C# program structure
 
Learn advanced java programming
Learn advanced java programmingLearn advanced java programming
Learn advanced java programming
 

More from Hemant Chetwani

More from Hemant Chetwani (12)

Simulated annealing in n - queens
Simulated annealing in n - queensSimulated annealing in n - queens
Simulated annealing in n - queens
 
Channel Capacity and transmission media
Channel Capacity and transmission mediaChannel Capacity and transmission media
Channel Capacity and transmission media
 
Pseudo Random Number
Pseudo Random NumberPseudo Random Number
Pseudo Random Number
 
CART – Classification & Regression Trees
CART – Classification & Regression TreesCART – Classification & Regression Trees
CART – Classification & Regression Trees
 
Types of Compilers
Types of CompilersTypes of Compilers
Types of Compilers
 
Socket & Server Socket
Socket & Server SocketSocket & Server Socket
Socket & Server Socket
 
Pumming Lemma
Pumming LemmaPumming Lemma
Pumming Lemma
 
Hash table
Hash tableHash table
Hash table
 
First pass of assembler
First pass of assemblerFirst pass of assembler
First pass of assembler
 
130410107010 exception handling
130410107010 exception handling130410107010 exception handling
130410107010 exception handling
 
Counters & time delay
Counters & time delayCounters & time delay
Counters & time delay
 
Bucket sort
Bucket sortBucket sort
Bucket sort
 

Recently uploaded

(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...ranjana rawat
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 

Recently uploaded (20)

(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 

DOT NET PROPERTIES AND INDEXERS

  • 1. ACTIVE LEARNING ASSIGNMENT FOR THE SUBJECT “DOT NET” PROPERTIES AND INDEXERS IN C# Guided By : - Nitin Patel (Assistance prof.) Prepared By :- Hemant H. Chetwani (130410107010 TY CE-II)
  • 2. Contents  Properties.  Accessors.  Example of property.  Indexers.  Use of indexers.  Example of indexer.  Difference of property & indexer.
  • 3. PROPERTIES • Properties are named members of classes, structures, and interfaces. Member variables or methods in a class or structures are called Fields. Properties are an extension of fields and are accessed using the same syntax.They use accessors through which the values of the private fields can be read, written, or manipulated. • Properties do not name the storage locations. Instead, they have accessors that read, write, or compute their values. • For example, let us have a class named Student, with private fields for age, name, and code.We cannot directly access these fields from outside the class scope, but we can have properties for accessing these private fields.
  • 4. ACCESSORS The accessor of a property contains the executable statements that helps in getting (reading or computing) or setting (writing) the property. In short getter and setter methods are known as accessors.
  • 5. Property : Simple Example public class Student { private string Name; public string name { get { return name; } set { name = value; } } } Student s = new Student(); s.Name = “Hemant"; Console.WriteLine(s);
  • 6. INDEXERS An indexer allows an object to be indexed such as an array.When you define an indexer for a class, this class behaves similar to a virtual array.You can then access the instance of this class using the array access operator ([ ]).
  • 7. USE OF INDEXERS • Declaration of behavior of an indexer is to some extent similar to a property. Similar to the properties, you use get and set accessors for defining an indexer. However, properties return or set a specific data member, whereas indexers returns or sets a particular value from the object instance. In other words, it breaks the instance data into smaller parts and indexes each part, gets or sets each part. • Defining a property involves providing a property name. Indexers are not defined with names, but with the this keyword, which refers to the object instance.The following example demonstrates the concept:
  • 8. Indexer: Simple Example public class ListBox { private string[] items; public string this[int index] { get { return items[index]; } set { items[index] = value; } } } ListBox listBox = new ListBox(); listBox[0] = "hello"; Console.WriteLine(listBox[0]);
  • 9. Difference between Property & Indexer Property Indexer Allows methods to be called as if they were public data members. Allows elements of an internal collection of an object to be accessed by using array notation on the object itself. Accessed through a simple name. Accessed through an index. Can be a static or an instance member. Must be an instance member. A get accessor of a property has no parameters. A get accessor of an indexer has the same formal parameter list as the indexer. A set accessor of a property contains the implicit value parameter. A set accessor of an indexer has the same formal parameter list as the indexer, and also to the value parameter.