fork download
  1. using System;
  2.  
  3. class Program
  4. {
  5. static void Main(string[] args)
  6. {
  7. MyArray fruit = new MyArray(-2, 1);
  8. fruit[-2] = "Apple";
  9. fruit[-1] = "Orange";
  10. fruit[0] = "Banana";
  11. fruit[1] = "Blackcurrant";
  12. Console.WriteLine(fruit[-1]); // Outputs "Orange"
  13. Console.WriteLine(fruit[0]); // Outputs "Banana"
  14. Console.WriteLine(fruit[-1,0]); // Output "O"
  15. }
  16. }
  17.  
  18. class MyArray
  19. {
  20. int _lowerBound;
  21. int _upperBound;
  22. string[] _items;
  23.  
  24. public MyArray(int lowerBound, int upperBound)
  25. {
  26. _lowerBound = lowerBound;
  27. _upperBound = upperBound;
  28. _items = new string[1 + upperBound - lowerBound];
  29. }
  30.  
  31. public string this[int index]
  32. {
  33. get { return _items[index - _lowerBound]; }
  34. set { _items[index - _lowerBound] = value; }
  35.  
  36. }
  37.  
  38. public string this[int word, int position]
  39. {
  40. get { return this[word].Substring(position, 1); }
  41. }
  42. }
  43.  
Success #stdin #stdout 0.03s 36856KB
stdin
Standard input is empty
stdout
Orange
Banana
O