





















I thought ArrayList.ToArray(Type) was for intrinsic types (int, string etc.) but forgot that one the facilitites of OOP is that types that we define can be treated as instinsic types for most occasions. Today I came across a code that showed the use of ArrayList.ToArray(Type) for a type defined by the programmer.
...
return (Contact[])mContacts.ToArray(typeof(Contact));
...
here mConstacts is of type ArrayList, and Contact is a class.
I was doing the following till now :-
C# :-
Contact[] contacts = new Contact[mContacts.Count];
mContacts.CopyTo(contacts);
return contacts;
I have yet to peek into the IL to see the difference/similarity between the two approaches in terms of internals, but the first one at least requires less code and fits in a single line. :-)
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。