language: C# (mono-2.8)
date: 315 days 23 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
 
class Program
{
    static void Main(string[] args)
    {
        MyArray fruit = new MyArray(-2, 1);
        fruit[-2] = "Apple";
        fruit[-1] = "Orange";
        fruit[0] = "Banana";
        fruit[1] = "Blackcurrant";
        Console.WriteLine(fruit[-1]);       // Outputs "Orange"
        Console.WriteLine(fruit[0]);        // Outputs "Banana"
        Console.WriteLine(fruit[-1,0]);     // Output "O"
    }
}
 
class MyArray
{
    int _lowerBound;
    int _upperBound;
    string[] _items;
 
    public MyArray(int lowerBound, int upperBound)
    {
        _lowerBound = lowerBound;
        _upperBound = upperBound;
        _items = new string[1 + upperBound - lowerBound];
    }
 
    public string this[int index]
    {
        get { return _items[index - _lowerBound]; }
        set { _items[index - _lowerBound] = value; }
 
    }
 
    public string this[int word, int position]
    {
        get { return this[word].Substring(position, 1); }
    }
}