Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You will need to create an object that can manage this.</p> <p>Think about what it will need to store per item. Basically, the data (e.g. <code>txtName</code>), and an expiry time. That means you probably will need a class or struct that just has those 2 elements.</p> <p>Your <code>ExpiringList</code> class will be a list of that type.</p> <p>Now you have your basic data structure (a collection/list of <code>ExpiringListItem</code>) you need to think about what operations you want to support. Currently you've listed AddToList, others would probably be RemoveFromList, Clear, and maybe iterating over all items.</p> <p>The only thing unique to your ExpiringList compared to a normal <code>List&lt;T&gt;</code> is that you want to automatically remove expired items. Therefore it would make sense to make your ExpiringList implement the interface <code>IList&lt;T&gt;</code> and use a private List internally, possibly you could make your list (and by necessity your <code>ExpiredListItem</code> class) generic.</p> <p>The tricky part, beyond understanding and implementing inheritance (a separate question really), is working out how to remove expired items.</p> <p>This would mean creating a method within your class that iterated (in reverse order) over your items, comparing their expiry time with the current time and removing expired ones.</p> <p>You could implement the interface simply by calling the appropriate methods on your internal list.</p> <p>You could say at this point, you're done, since you just call that method periodically to ensure sure all expired items are gone before you use the items in the list.</p> <p>Maybe a better option would be to call this method before running the method on the internal list. Depending on how you will use your list this may be overkill.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload