C
CMM
First let me say that maybe I'm having a "duh" moment and perhaps I'm
missing something... but it seems to me that no one thing in the
System.Collections namespace (even in .NET 2.0) even comes close to the
still-useful-today VB intrinsic Collection. Here's the challenge (I know I'm
totally missing something here)....
Implement a full featured MRU (Most Recently Used) list using
System.Collections.
Use Case:
1) Current MRU: MyNotes.txt, MySpreadsheet1.txt, SomeOtherFile.txt
2) User opens "myspreadsheet1.txt" (note the case... the file was renamed
sometime between step 1and2
3) New MRU: MyNotes.txt, SomeOtherFile.txt, *myspreadsheet1.txt*
Requirements:
1) Items must be stored in their original case, but searches on the
collection must be case-insensitive. No storing items using ToLower()
cheating crap to work around the framework's case-sensitive collections.
2) Items must be stored oldest to newest (or newest to oldest... it doesn't
really matter).
3) When adding a new item (case preserved), a matching item (case
insensitive) already in the collection gets popped out.
Well, Dictionary(Of String) seems to be the answer.... as the default
comparator for Key is case-insensitive...
MRUDictionary.Remove(file) <-- case insensitive
MRUDictionary.Add(file, file) <-- new case preserved
BUT...
4) The collection should allow access by index AND it must be "trimmable."
Sub TrimMRU()
If MRU.Count > 10 Then
Dim delta As Integer = MRU.Count - 10
For tally As Integer = 1 To delta
MRU.RemoveAt(0) '<-- oldest items removed
Next tally
End If
End Sub
Dictionary does not support this. You cannot access items "by index."
Anyone have an answer? This is easily done using "Collection"...... but is
there no "framework" equivalent without doing a lot of "kludgy" code?
missing something... but it seems to me that no one thing in the
System.Collections namespace (even in .NET 2.0) even comes close to the
still-useful-today VB intrinsic Collection. Here's the challenge (I know I'm
totally missing something here)....
Implement a full featured MRU (Most Recently Used) list using
System.Collections.
Use Case:
1) Current MRU: MyNotes.txt, MySpreadsheet1.txt, SomeOtherFile.txt
2) User opens "myspreadsheet1.txt" (note the case... the file was renamed
sometime between step 1and2
3) New MRU: MyNotes.txt, SomeOtherFile.txt, *myspreadsheet1.txt*
Requirements:
1) Items must be stored in their original case, but searches on the
collection must be case-insensitive. No storing items using ToLower()
cheating crap to work around the framework's case-sensitive collections.
2) Items must be stored oldest to newest (or newest to oldest... it doesn't
really matter).
3) When adding a new item (case preserved), a matching item (case
insensitive) already in the collection gets popped out.
Well, Dictionary(Of String) seems to be the answer.... as the default
comparator for Key is case-insensitive...
MRUDictionary.Remove(file) <-- case insensitive
MRUDictionary.Add(file, file) <-- new case preserved
BUT...
4) The collection should allow access by index AND it must be "trimmable."
Sub TrimMRU()
If MRU.Count > 10 Then
Dim delta As Integer = MRU.Count - 10
For tally As Integer = 1 To delta
MRU.RemoveAt(0) '<-- oldest items removed
Next tally
End If
End Sub
Dictionary does not support this. You cannot access items "by index."
Anyone have an answer? This is easily done using "Collection"...... but is
there no "framework" equivalent without doing a lot of "kludgy" code?