Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Logic/Syntax for shifting all items in List<string> by +1 place</string>

Logic/Syntax for shifting all items in List<string> by +1 place</string>

Scheduled Pinned Locked Moved C#
tutorialquestion
6 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Abydosgater
    wrote on last edited by
    #1

    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

    P D L M 4 Replies Last reply
    0
    • A Abydosgater

      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

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      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

      My blog | My articles | MoXAML PowerToys

      1 Reply Last reply
      0
      • A Abydosgater

        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

        D Offline
        D Offline
        DaveyM69
        wrote on last edited by
        #3

        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)

        1 Reply Last reply
        0
        • A Abydosgater

          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

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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

          L 1 Reply Last reply
          0
          • L Lost User

            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

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            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).


            1 Reply Last reply
            0
            • A Abydosgater

              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

              M Offline
              M Offline
              Mark Churchill
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups