【发布时间】:2015-07-18 10:01:33
【问题描述】:
这可能是一个非常基本的问题,但真的不知道如何解决。我想创建以下内容:
public class MyArray
{
List<KeyValuePair<int, object>> myList = new List<KeyValuePair<int, object>>();
public void Set_Value(int index, object value)
{
myList = myList.Where(a => a.Key != index).ToList();
myList.Add(new KeyValuePair<int, object>(index, value));
}
public object Get_Value(int index)
{
if (myList.Any(a => a.Key == index)) return myList.FirstOrDefault(a => a.Key == index).Value;
else return null;
}
}
class Program
{
static void Main(string[] args)
{
MyArray array = new MyArray();
array[0] = "Hello world!";
}
}
制作一个我自己操作的数组...
【问题讨论】:
-
那么您的数组实现有什么问题?
-
对不起,它是重复的,我在 google 中找不到它...
-
感谢您的回答
-
还值得注意的是,您对这种机制的实现在很多方面都超级效率低下。
标签: c#