Code:public int Add(object value) { object[] tmp = new object[_items.Length + 1]; for (int i = 0; i < _items.Length; i++) { tmp[i] = _items[i]; } tmp[tmp.Length - 1] = value; _items = tmp; return tmp.Length - 1; }
Code:public int Add(object value) { object[] tmp = new object[_items.Length + 1]; for (int i = 0; i < _items.Length; i++) { tmp[i] = _items[i]; } tmp[tmp.Length - 1] = value; _items = tmp; return tmp.Length - 1; }
"Array.Resize()" might be faster than your loop.
Devoted my life to programming...
i want to implement Ilist method Add(object value) not resize how do you think if i do in one for loop will it be faster than this?
can you show me how can it be done? your version
Maybe you should forget about speed optimization until you are comfortable with the language...
Devoted my life to programming...
Why aren't you just using a List<object> instead of an array, which already does what you're trying to do?
If you understand what you're doing, you're not learning anything.