Indexer (programming): Difference between revisions

Content deleted Content added
No edit summary
Adding local short description: "Object-oriented programming concept", overriding Wikidata description "overloadable collection indexing operator"
 
(One intermediate revision by one other user not shown)
Line 1:
{{Short description|Object-oriented programming concept}}
In [[object-oriented programming]], an '''indexer''' allows instances of a particular class or struct to be indexed just like arrays.<ref>{{cite web|access-date=2011-08-01 |author=jagadish980 |date=2008-01-29 |website=SURESHKUMAR.NET FORUMS |title=C# - What is an indexer in C# |url=http://forums.sureshkumar.net/vb-asp-net-interview-technical-questions/16320-c-what-indexer-c.html |archive-url=https://web.archive.org/web/20090922193214/http://forums.sureshkumar.net/vb-asp-net-interview-technical-questions/16320-c-what-indexer-c.html |archive-date=September 22, 2009 }}</ref> It is a form of [[operator overloading]].
 
Line 115 ⟶ 116:
In [[PHP]] indexing can be implemented via the predefined {{code|ArrayAccess}} interface,<ref>{{cite web|url=https://www.php.net/manual/en/class.arrayaccess.php|title=PHP ArrayAccess interface}}</ref>
<syntaxhighlight lang="php">
<?php
class Vector implements ArrayAccess
{
Line 140:
for ($i = 0; $i < $vector->size; $i++) $vector[$i] = $i + 1;
for ($i = 0; $i < $vector->size; $i++) print "{$vector[$i]}\n";
?>
</syntaxhighlight>
 
Line 220 ⟶ 219:
 
== See also ==
{{Portal|Computer programming}}
* [[Mutator method]]