i have this following code. It is not adding new key values to the dictionary….whats wrong??
while(true)
{
TimeSpan t = // some timespan which is updating every second
int value = // some value associated with timespan
Dictionary<TimeSpan,int> _dict = new Dictionary<TimeSpan,int>();
_dict.Add(t,value);
}
The problem is that you are instantiating a brand new dictionary each time the loop executes
Try this:
As a side note, it might make more sense to just use the total elapsed ticks or milliseconds as the key instead of a time-span object