Lets assume I have plenty of strings that need processing, I like to place the last processed string in memory to avoid repeated processing against it. I only need to record the last 100 strings, which means if I use
List<string> oldString
after oldString.Add()
, I have to use oldString.TakeFromEnd(100)
As you know, TakeFromEnd()
not exist, which means if I go this path, I have to write lots of things to keep a 100 length List
which would lead to bad performance I can imagine.
I'd like to ask, is there any pre-made in system Class that just holds a fixed amount of data, and throws away oldest data when a new one is added. Thanks
[EDIT]
Queue<string>
is very good indeed, use .Any()
to check if already exist, use .Enqueue()
to add (not Equeue as answered below, it shot a N), use .Count
to check length, and .Dequeue()
to remove the first added one.