Is there a faster way to clone the items than what is shown below?
private List<T> CloneItems(List<T> itemsToClone) {
lock (dataLocker) {
Stopwatch sw = Stopwatch.StartNew();
int numItems = itemsToClone.Count;
List<T> itemsToBeReturned = new List<T>(numItems);
for (int i = 0; i < numItems; i++) {
itemsToBeReturned.Add((T)itemsToClone[i].Clone());
}
Debug.WriteLine("CloneItems(ms): " + sw.Elapsed.TotalMilliseconds.ToString("F3"));
return itemsToBeReturned;
}
}
EDIT: I need a deep copy and am currently using it with the following object:
public class TimestampedDouble {
public long Timestamp { get; set; }
public double Voltage { get; set; }
public double Current { get; set; }
...
public override object Clone() {
return MemberwiseClone();
}
}