diff options
| author | ven <vendethiel@hotmail.fr> | 2014-12-10 16:27:15 +0100 | 
|---|---|---|
| committer | ven <vendethiel@hotmail.fr> | 2014-12-10 16:27:15 +0100 | 
| commit | 9c31862620e2f2d48647c6fbb08034ff94b98fcc (patch) | |
| tree | 0acb65dd2f0e9faddf0ad0b3d514ac210f634ac5 /csharp.html.markdown | |
| parent | 69e6f40785cb7ae2c6c382253c39fe9dede810ff (diff) | |
| parent | 9a8d8f0e5da4af6ddf18124f2cc203dcf57b52e5 (diff) | |
Merge pull request #885 from adriancooney/csharp-en-indexers
[c#/en] Added an example of a custom indexer.
Diffstat (limited to 'csharp.html.markdown')
| -rw-r--r-- | csharp.html.markdown | 17 | 
1 files changed, 17 insertions, 0 deletions
| diff --git a/csharp.html.markdown b/csharp.html.markdown index f6708590..47dd9683 100644 --- a/csharp.html.markdown +++ b/csharp.html.markdown @@ -678,6 +678,23 @@ on a new line! ""Wow!"", the masses cried";              private set;          } +        // It's also possible to define custom Indexers on objects. +        // All though this is not entirely useful in this example, you +        // could do bicycle[0] which yields "chris" to get the first passenger or +        // bicycle[1] = "lisa" to set the passenger. (of this apparent quattrocycle) +        private string[] passengers = { "chris", "phil", "darren", "regina" } + +        public string this[int i] +        { +            get { +                return passengers[i]; +            } + +            set { +                return passengers[i] = value; +            } +        } +          //Method to display the attribute values of this Object.          public virtual string Info()          { | 
