AlHal2
asked on
Record date and time that an item was added to a C# dictionary
I'm using C# in Visual Studio 2017 and have a generic dictionary <string, Widget>
Without changing the widget class is it possible for the dictionary to store when each key value pair was added?
If it was added more than a minute ago then delete it or at least ignore it.
Without changing the widget class is it possible for the dictionary to store when each key value pair was added?
If it was added more than a minute ago then delete it or at least ignore it.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thanks all. Would it be worth creating a class that inherits from Widget then using that derived class instead of Widget?
I would think you'd go the other way around. Otherwise, every class you create in the future which has the same kind of requirement will require two classes. If you flip your inheritance the other way--where Widget inherits a base--then you have only one class to inherit from for all future classes. However, this does box you into a particular inheritance hierarchy, which can also be problematic. Using a generic class like what I described above can give you a bit of flexibility in not having to define an inheritance hierarchy just for the purpose of recording the time.
ASKER
Thanks.
As Bill says - with your current situation the answer is no.