Hello Forum,
I have a collection class (inherited from System.Collections.CollectionBase). I want to return the contents in a list<>. I do this with the following function:
public List Clone()
{
List objMyCustomBlockList = new List();
MyCustomBlock[] objMyCustomBlockArray= new MyCustomBlock[this.List.Count];
this.List.CopyTo(objMyCustomBlockArray, 0);
objMyCustomBlockList.AddRange(objMyCustomBlockArray);
return objMyCustomBlockList;
}
Is there a faster way of doing this (performance)?
Is there a more elegant way of writing this code (less code)?
Thank you.
Nitin SontakkePosted Jul 25, 2016, 11:46 PM
Looks good tome, except I didn't get the "this" part of the code. Is this an extension method?
Ert TrePosted Jul 25, 2016, 12:21 PM
Manas MohapatraPosted Jul 23, 2016, 6:57 AM