假设我有一个类型为 class 的对象数组,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# 中存储和发布数组的方式的一些额外信息,我将不胜感激,以便消除我遇到的任何疑问和困惑。