每次运行后都清空数据字典 [英] Null out data dictionary after every run
本文介绍了每次运行后都清空数据字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个非常难以回答的问题,希望它有意义。我正在阅读两种不同类型的文本文件并检查字典中的记录。文本文件可以有不同的日期,所以我需要在检查一个文件之后转储字典,然后再通过数据库读取以获取文本文件的新日期。每次跑步后我怎么愚蠢的字典?
我尝试过:
I have a very difficult question to ask, hopefully it will make sense. I am reading two different types of text files and checking the records within a dictionary. The textfiles can have different dates so I need to dump the dictionary after it checks one file and read again through database to fetch the new date of the textfile. How do I dumb the dictionary after every run?
What I have tried:
private Dictionary<DateTime, Dictionary<string, long>> DataByNum;
private Dictionary<DateTime, Dictionary<string, long>> DataByID;
private Dictionary<string, long> GetNumData(DateTime DailyFileDate)
{
DailyFileDate = DailyFileDate.Date;
if (DataByNum == null || !DataByNum.ContainsKey(DailyFileDate))
{
CacheData(DailyFileDate);
}
return DataByNum[DailyFileDate];
}
private Dictionary<string, long> GetIDData(DateTime DailyFileDate)
{
DailyFileDate = DailyFileDate.Date;
if (DataByID == null || !DataByID.ContainsKey(DailyFileDate))
{
CacheData(DailyFileDate);
}
return DataByID[DailyFileDate];
}
private void CacheData(DateTime DailyFileDate)
{
DailyFileDate = DailyFileDate.Date;
if (DataByNum == null)
{
DataByNum = new Dictionary<DateTime, Dictionary<string, long>>();
}
if (DataByID == null)
{
DataByID = new Dictionary<DateTime, Dictionary<string, long>>();
}
var result = ExtractData(DailyFileDate);
foreach (DataRow row in result)
{
var date = DateTime.Parse(row.GetString("FileDate")).Date;
if (!DataByNum.ContainsKey(date))
{
DataByNum[date] = new Dictionary<string, long>();
DataByNum[date].Add(row.GetString("Num"), row.GetLong("RID").Value);
}
if (!DataByID.ContainsKey(date))
{
DataByID[date] = new Dictionary<string, long>();
DataByID[date].Add(row.GetString("CustomerID"), row.GetLong("RID").Value);
}
}
推荐答案
您可以调用字典。清除()
,或者只是用new
重新实例化。
You can either calldictionary.Clear()
, or simply re-instantiate it withnew
.
这篇关于每次运行后都清空数据字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文