fork(2) download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. var list = new PositiveNegativeList<string>();
  9. list.Add("test");
  10. Console.WriteLine(list[0]);
  11. }
  12. }
  13.  
  14. public class PositiveNegativeList<T>
  15. {
  16. List<T> PositiveList;
  17. List<T> NegativeList;
  18.  
  19. public PositiveNegativeList()
  20. {
  21. PositiveList = new List<T>();
  22. NegativeList = new List<T>();
  23. }
  24.  
  25. public T this[int index]
  26. {
  27. get
  28. {
  29. if (index < 0)
  30. return NegativeList[index * -1];
  31. else
  32. return PositiveList[index];
  33. }
  34.  
  35. set
  36. {
  37. if (index < 0)
  38. NegativeList[index * -1] = value;
  39. else
  40. PositiveList[index] = value;
  41. }
  42. }
  43.  
  44. public void Add(T item)
  45. {
  46. PositiveList.Add(item);
  47. }
  48. }
  49.  
Success #stdin #stdout 0.02s 33912KB
stdin
Standard input is empty
stdout
test