How to obtain the index of the last entry in a collection
-
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
-
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
What's the SpinDataCollection type? a Generic collection? An ArrayList?? What???
I'm on a Fuzzy State: Between 0 an 1
-
What's the SpinDataCollection type? a Generic collection? An ArrayList?? What???
I'm on a Fuzzy State: Between 0 an 1
-
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
-
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
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
-
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
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.
-
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