المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Removing values in a dictionary [modified]



C# Programming
01-05-2010, 02:12 PM
I have a dictionary call timeDate. where DriveDT is an object.
static Dictionary timeDate = new Dictionary();

I want to remove the value from the dictionary, the line im using is in the section else //unload

But the line isnt working.
timeDate.Remove(key);


private static void extractSE(string filePath)
{
StreamReader textIn = new StreamReader(filePath);

do
{
string text = textIn.ReadLine();

bool mail = text.Contains("Mail");

if(!mail)
{
if ((text != ""))
{
int indexofTO = text.IndexOf("to");
int indexofSLOT = text.IndexOf("Slot");


if (indexofSLOT < indexofTO) //load
{
int indexofInfo = text.IndexOf("Info");
string dtTxt = text.Substring(0, (indexofInfo - 1));
DateTime dt = DateTime.Parse(dtTxt);
string data = text.Substring(indexofInfo);
string key = text.Substring(indexofSLOT, (indexofTO - indexofSLOT - 1));
timeDate.Add(key, new DriveDT(dt, data));

}
else //unload
{
string key = text.Substring((indexofTO + 2));


timeDate.Remove(key);
}
}
}
}
while (!textIn.EndOfStream);

}



Is this more clear?

modified on Monday, January 4, 2010 11:17 AM