using System;
using System.Collections.Generic;
public class Test
{
public static void Main()
{
var list = new PositiveNegativeList<string>();
list.Add("test");
Console.WriteLine(list[0]);
}
}
public class PositiveNegativeList<T>
{
List<T> PositiveList;
List<T> NegativeList;
public PositiveNegativeList()
{
PositiveList = new List<T>();
NegativeList = new List<T>();
}
public T this[int index]
{
get
{
if (index < 0)
return NegativeList[index * -1];
else
return PositiveList[index];
}
set
{
if (index < 0)
NegativeList[index * -1] = value;
else
PositiveList[index] = value;
}
}
public void Add(T item)
{
PositiveList.Add(item);
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYzsKCnB1YmxpYyBjbGFzcyBUZXN0CnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBNYWluKCkKCXsKCQl2YXIgbGlzdCA9IG5ldyBQb3NpdGl2ZU5lZ2F0aXZlTGlzdDxzdHJpbmc+KCk7CgkJbGlzdC5BZGQoInRlc3QiKTsKCQlDb25zb2xlLldyaXRlTGluZShsaXN0WzBdKTsKCX0KfQoKICAgIHB1YmxpYyBjbGFzcyBQb3NpdGl2ZU5lZ2F0aXZlTGlzdDxUPgogICAgewogICAgICAgIExpc3Q8VD4gUG9zaXRpdmVMaXN0OwogICAgICAgIExpc3Q8VD4gTmVnYXRpdmVMaXN0OwoKICAgICAgICBwdWJsaWMgUG9zaXRpdmVOZWdhdGl2ZUxpc3QoKQogICAgICAgIHsKICAgICAgICAgICAgIFBvc2l0aXZlTGlzdCA9IG5ldyBMaXN0PFQ+KCk7CiAgICAgICAgICAgICBOZWdhdGl2ZUxpc3QgPSBuZXcgTGlzdDxUPigpOwogICAgICAgIH0KICAgICAgICAKICAgICAgICBwdWJsaWMgVCB0aGlzW2ludCBpbmRleF0KICAgICAgICB7CiAgICAgICAgICAgIGdldAogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBpZiAoaW5kZXggPCAwKQogICAgICAgICAgICAgICAgICAgcmV0dXJuIE5lZ2F0aXZlTGlzdFtpbmRleCAqIC0xXTsKICAgICAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgICAgIHJldHVybiBQb3NpdGl2ZUxpc3RbaW5kZXhdOwogICAgICAgICAgICB9CgogICAgICAgICAgICBzZXQKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaWYgKGluZGV4IDwgMCkKICAgICAgICAgICAgICAgICAgIE5lZ2F0aXZlTGlzdFtpbmRleCAqIC0xXSA9IHZhbHVlOwogICAgICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgICAgUG9zaXRpdmVMaXN0W2luZGV4XSA9IHZhbHVlOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIAogICAgICAgIHB1YmxpYyB2b2lkIEFkZChUIGl0ZW0pCiAgICAgICAgewogICAgICAgICAgICBQb3NpdGl2ZUxpc3QuQWRkKGl0ZW0pOwogICAgICAgIH0KICAgIH0K