问题
I am working on some code that is written in C#. In this app, I have a custom collection defined as follows:
public class ResultList<T> : IEnumerable<T>
{
public List<T> Results { get; set; }
public decimal CenterLatitude { get; set; }
public decimal CenterLongitude { get; set; }
}
After I query my database and populate a ResultList, I am storing it in in-memory cache. This way I don't need to hit my database every time. This approach works the first time. However, on subsequent loads, it doesn't work because the ResultList that gets pulled from the Cache has been updated. I suspect because a deep copy is happening.
How do I get a shallow copy of a ResultList?
来源:https://stackoverflow.com/questions/11073196/shallow-copy-of-a-custom-c-sharp-object