Shallow Copy of a Custom C# Object

狂风中的少年 提交于 2019-12-13 04:28:35

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!