Logic/Syntax for shifting all items in List<string> by +1 place</string>
-
Hi, Ive been trying to figure out how to go about doing this for a few hours, Was wondering if someone could offer some advice. What i have is "List Files = new .." containing a number of file paths in order of last opened. The list is LIMITED to only holding 10 items. When a new file is opened, i want to shift all of the items in the list by +1 place. So Files[1] goes to Files[2] ... and Files[2] goes to Files[3] and so on. So then i can keep adding new files, they will go to Files[1] and all of the others move up a position. Anyone any advice? If what i said even makes the slightest of sense? Thanks for reading my confusing stuff ;P
-
Hi, Ive been trying to figure out how to go about doing this for a few hours, Was wondering if someone could offer some advice. What i have is "List Files = new .." containing a number of file paths in order of last opened. The list is LIMITED to only holding 10 items. When a new file is opened, i want to shift all of the items in the list by +1 place. So Files[1] goes to Files[2] ... and Files[2] goes to Files[3] and so on. So then i can keep adding new files, they will go to Files[1] and all of the others move up a position. Anyone any advice? If what i said even makes the slightest of sense? Thanks for reading my confusing stuff ;P
Do a list.Insert to put the item in at the first place, and a list.Remove to remove the last item from the list.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
-
Hi, Ive been trying to figure out how to go about doing this for a few hours, Was wondering if someone could offer some advice. What i have is "List Files = new .." containing a number of file paths in order of last opened. The list is LIMITED to only holding 10 items. When a new file is opened, i want to shift all of the items in the list by +1 place. So Files[1] goes to Files[2] ... and Files[2] goes to Files[3] and so on. So then i can keep adding new files, they will go to Files[1] and all of the others move up a position. Anyone any advice? If what i said even makes the slightest of sense? Thanks for reading my confusing stuff ;P
I recently implemented something similar. The way I did it was to have a class that contained the 'friendly' filename, filepath and date. I used IComparable to sort them by date descending and used a generic list and it's Sort method. Then I just displayed the number of entries I was interested in by getting those just that many from the beginning of the List. Doing it that way, you can automatically 'reverse fill' the list if you give the user the option to remove an entry - similar to the way visual studio does.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) -
Hi, Ive been trying to figure out how to go about doing this for a few hours, Was wondering if someone could offer some advice. What i have is "List Files = new .." containing a number of file paths in order of last opened. The list is LIMITED to only holding 10 items. When a new file is opened, i want to shift all of the items in the list by +1 place. So Files[1] goes to Files[2] ... and Files[2] goes to Files[3] and so on. So then i can keep adding new files, they will go to Files[1] and all of the others move up a position. Anyone any advice? If what i said even makes the slightest of sense? Thanks for reading my confusing stuff ;P
-
What happens if you open a file that's already part of the collection? If it should only work for new files being opened, then a Queue[^] will do the job, otherwise could use a LinkedList[^]. regards
Hi, for every potentially new file, you can remove it (which will fail silently if not present), then insert it at the most-recently-used side. When the remove failed (see return value), you may want to remove the one at the least-recently-used side instead. :)
Luc Pattyn [Forum Guidelines] [My Articles]
I use ListBoxes for line-oriented text output (not TextBoxes), and PictureBoxes for pictures (not drawings).
-
Hi, Ive been trying to figure out how to go about doing this for a few hours, Was wondering if someone could offer some advice. What i have is "List Files = new .." containing a number of file paths in order of last opened. The list is LIMITED to only holding 10 items. When a new file is opened, i want to shift all of the items in the list by +1 place. So Files[1] goes to Files[2] ... and Files[2] goes to Files[3] and so on. So then i can keep adding new files, they will go to Files[1] and all of the others move up a position. Anyone any advice? If what i said even makes the slightest of sense? Thanks for reading my confusing stuff ;P
This is what a Stack or Queue is used for... Either that or just use List.Add, and then display them in reverse order ;)
Mark Churchill Director, Dunn & Churchill Pty Ltd Free Download: Diamond Binding: The simple, powerful, reliable, and effective data layer toolkit for Visual Studio.
Entanglar: .Net game engine featuring automatic networking and powerful HLSL gfx binding.