【发布时间】:2013-08-01 11:20:17
【问题描述】:
假设我有一个类型为 InvoiceItem 的对象数组,定义如下:
private class InvoiceItem
{
public DateTime InvoiceDate { get; set; }
public int InvoiceID { get; set; }
public byte ItemType { get; set; }
public short Quantity { get; set; }
public string ProductName { get; set; }
public decimal Price { get; set; }
public decimal Amount{ get; set; }
public InvoiceItem(DateTime InvoiceDate,int InvoiceID, short Quantity, string ProductName, decimal Price,decimal Amount, byte ItemType)
{
this.InvoiceDate = InvoiceDate;
this.InvoiceID = InvoiceID;
this.Quantity = Quantity;
this.ProductName = ProductName;
this.Price = Price;
this.Amount = Amount;
this.ItemType = ItemType;
}
}
我尝试将我的项目缓存在一个名为invoiceItemsCache的数组中
private InvoiceItem[] invoiceItemsCache;
每次我想刷新我的缓存时,我都会重新初始化我的数组:
invoiceItemsCache = new InvoiceItem[count];
我需要做一些事情来释放之前缓存使用的内存,还是自动完成?如果有人提供一些有关在 C# 中存储和发布数组的方式的额外信息,我将不胜感激,以便消除我遇到的任何疑问和困惑。
【问题讨论】:
标签: c# arrays memory-management