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. How to obtain the index of the last entry in a collection

How to obtain the index of the last entry in a collection

Scheduled Pinned Locked Moved C#
databasetutorial
8 Posts 4 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.
  • H Offline
    H Offline
    haz13
    wrote on last edited by
    #1

    I am using collections for the first time and can't seem to figure out how to obtain the index of the last entry in the collection. I am guessing that I could use IndexOf() or LastIndexOf() methods, but not sure what to pass into the method. Here is the code public static class NumberProcessing { public static void UpdateSpinDataCollection() { SpinDataCollection.Add(new SpinData SpinNumber, CurrentNumber, Colour OddorEven); //Trying here to get index of last entry in collection SDCPointer = (short)SpinDataCollection.LastIndexOf(); //Test MessageBox.Show("SDCPointer:\t" + SDCPointer.ToString()); } }

    Haz

    G H 2 Replies Last reply
    0
    • H haz13

      I am using collections for the first time and can't seem to figure out how to obtain the index of the last entry in the collection. I am guessing that I could use IndexOf() or LastIndexOf() methods, but not sure what to pass into the method. Here is the code public static class NumberProcessing { public static void UpdateSpinDataCollection() { SpinDataCollection.Add(new SpinData SpinNumber, CurrentNumber, Colour OddorEven); //Trying here to get index of last entry in collection SDCPointer = (short)SpinDataCollection.LastIndexOf(); //Test MessageBox.Show("SDCPointer:\t" + SDCPointer.ToString()); } }

      Haz

      G Offline
      G Offline
      Gonzalo Brusella
      wrote on last edited by
      #2

      What's the SpinDataCollection type? a Generic collection? An ArrayList?? What???

      I'm on a Fuzzy State: Between 0 an 1

      H 1 Reply Last reply
      0
      • G Gonzalo Brusella

        What's the SpinDataCollection type? a Generic collection? An ArrayList?? What???

        I'm on a Fuzzy State: Between 0 an 1

        H Offline
        H Offline
        haz13
        wrote on last edited by
        #3

        Sorry, it is a generic collection. public static List SpinDataCollection = new List();

        Haz

        H J 2 Replies Last reply
        0
        • H haz13

          Sorry, it is a generic collection. public static List SpinDataCollection = new List();

          Haz

          H Offline
          H Offline
          haz13
          wrote on last edited by
          #4

          The pointy brackets containing the bits have been removed from the code by the editor in my previous reply, not sure how to override that when posting here.

          Haz

          J D 2 Replies Last reply
          0
          • H haz13

            Sorry, it is a generic collection. public static List SpinDataCollection = new List();

            Haz

            J Offline
            J Offline
            Judah Gabriel Himango
            wrote on last edited by
            #5

            And you want to get the index of the last entry in the collection?

            int lastIndex = spinDataCollection.Count - 1;

            Tech, life, family, faith: Give me a visit. I'm currently blogging about: And in this corner, the Party of Allah The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

            1 Reply Last reply
            0
            • H haz13

              The pointy brackets containing the bits have been removed from the code by the editor in my previous reply, not sure how to override that when posting here.

              Haz

              J Offline
              J Offline
              Judah Gabriel Himango
              wrote on last edited by
              #6

              haz13 wrote:

              The pointy brackets containing the bits have been removed from the code by the editor in my previous reply, not sure how to override that when posting here.

              Put the following characters together for a "less than" character: < When you post it, it will look like < For "greater than" character, use the combination >, which will result in > Alternately, you can check the "Ignore HTML tags in this message (good for code snippets)" checkbox when you go to post, which will ignore HTML symbols such as the "greater than" and "less than" characters.

              Tech, life, family, faith: Give me a visit. I'm currently blogging about: And in this corner, the Party of Allah The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

              1 Reply Last reply
              0
              • H haz13

                The pointy brackets containing the bits have been removed from the code by the editor in my previous reply, not sure how to override that when posting here.

                Haz

                D Offline
                D Offline
                Dustin Metzgar
                wrote on last edited by
                #7

                No, the editor doesn't remove them. Consider it as html. You can check the little check box to tell it to ignore html tags or you can replace your <'s with <'s and >'s with >'s.


                Logifusion[^] If not entertaining, write your Congressman.

                1 Reply Last reply
                0
                • H haz13

                  I am using collections for the first time and can't seem to figure out how to obtain the index of the last entry in the collection. I am guessing that I could use IndexOf() or LastIndexOf() methods, but not sure what to pass into the method. Here is the code public static class NumberProcessing { public static void UpdateSpinDataCollection() { SpinDataCollection.Add(new SpinData SpinNumber, CurrentNumber, Colour OddorEven); //Trying here to get index of last entry in collection SDCPointer = (short)SpinDataCollection.LastIndexOf(); //Test MessageBox.Show("SDCPointer:\t" + SDCPointer.ToString()); } }

                  Haz

                  H Offline
                  H Offline
                  haz13
                  wrote on last edited by
                  #8

                  Thank you all :)

                  Haz

                  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