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. when a method is called i want to get first index value from an arraylist and when the same methid is called nxt time i want to get the second index value from the same arraylist...how?

when a method is called i want to get first index value from an arraylist and when the same methid is called nxt time i want to get the second index value from the same arraylist...how?

Scheduled Pinned Locked Moved C#
questiondatabasegraphicsdata-structureshelp
3 Posts 3 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.
  • M Offline
    M Offline
    merryjoy000
    wrote on last edited by
    #1

    when a method is called i want to get first index value from an arraylist and when the same method is called next time i want to get the second index value from the same arraylist...how can i do that? using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Collections; namespace roseapp2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } public ArrayList MPN = new ArrayList(); public string[,] Modems = new string[,] { {"Apple", "Banana", "81563840", "Damson"}, {"Elderberry", "Fig", "81547907", "Huckleberry"}, {"Indian Prune", "Jujube", "98764343322", "Lime"} }; public string arrayValue; private void button1_Click_1(object sender, EventArgs e) { // getphnum(); RoundRobin(); } private int z = 0; public void RoundRobin() { if (Modems == null) throw new ArgumentNullException("Modem"); if (Modems.Length < 0) return; //int Count = 0; int i; int x = Modems.Length/4; MessageBox.Show(Convert.ToString(x)); for (i = 0; i < x; i++) { string a = Modems[i, 2]; MessageBox.Show(a); arrayValue = a; MPN.Add(arrayValue); } for (int a = 0; a < MPN.Count; a++) { MessageBox.Show("ARRAY VALUE for index "+a+" "+Convert.ToString(MPN[a])); } } public void getphnum() { z++; MessageBox.Show(Convert.ToString(z)); } } } in this when the getphnum() is called one time i wnat to get firts index value(ie index 0 ph number)ie MPN arraylist.ANd when next time when getphnum () is called i want to get index 1 value from arraylist MPN.(ie the same arraylist from which i call my first array index value).. can somebody help meeeeeeeeeeee :| :|

    K D 2 Replies Last reply
    0
    • M merryjoy000

      when a method is called i want to get first index value from an arraylist and when the same method is called next time i want to get the second index value from the same arraylist...how can i do that? using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Collections; namespace roseapp2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } public ArrayList MPN = new ArrayList(); public string[,] Modems = new string[,] { {"Apple", "Banana", "81563840", "Damson"}, {"Elderberry", "Fig", "81547907", "Huckleberry"}, {"Indian Prune", "Jujube", "98764343322", "Lime"} }; public string arrayValue; private void button1_Click_1(object sender, EventArgs e) { // getphnum(); RoundRobin(); } private int z = 0; public void RoundRobin() { if (Modems == null) throw new ArgumentNullException("Modem"); if (Modems.Length < 0) return; //int Count = 0; int i; int x = Modems.Length/4; MessageBox.Show(Convert.ToString(x)); for (i = 0; i < x; i++) { string a = Modems[i, 2]; MessageBox.Show(a); arrayValue = a; MPN.Add(arrayValue); } for (int a = 0; a < MPN.Count; a++) { MessageBox.Show("ARRAY VALUE for index "+a+" "+Convert.ToString(MPN[a])); } } public void getphnum() { z++; MessageBox.Show(Convert.ToString(z)); } } } in this when the getphnum() is called one time i wnat to get firts index value(ie index 0 ph number)ie MPN arraylist.ANd when next time when getphnum () is called i want to get index 1 value from arraylist MPN.(ie the same arraylist from which i call my first array index value).. can somebody help meeeeeeeeeeee :| :|

      K Offline
      K Offline
      Kashif Sabir
      wrote on last edited by
      #2

      Take a static class variable and initialize it with the index of array and when you call the method again just add 1 to that variable i.e use that variable like a counter hope this helps sorry for the bad english. If thats not what you want then let me know

      1 Reply Last reply
      0
      • M merryjoy000

        when a method is called i want to get first index value from an arraylist and when the same method is called next time i want to get the second index value from the same arraylist...how can i do that? using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Collections; namespace roseapp2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } public ArrayList MPN = new ArrayList(); public string[,] Modems = new string[,] { {"Apple", "Banana", "81563840", "Damson"}, {"Elderberry", "Fig", "81547907", "Huckleberry"}, {"Indian Prune", "Jujube", "98764343322", "Lime"} }; public string arrayValue; private void button1_Click_1(object sender, EventArgs e) { // getphnum(); RoundRobin(); } private int z = 0; public void RoundRobin() { if (Modems == null) throw new ArgumentNullException("Modem"); if (Modems.Length < 0) return; //int Count = 0; int i; int x = Modems.Length/4; MessageBox.Show(Convert.ToString(x)); for (i = 0; i < x; i++) { string a = Modems[i, 2]; MessageBox.Show(a); arrayValue = a; MPN.Add(arrayValue); } for (int a = 0; a < MPN.Count; a++) { MessageBox.Show("ARRAY VALUE for index "+a+" "+Convert.ToString(MPN[a])); } } public void getphnum() { z++; MessageBox.Show(Convert.ToString(z)); } } } in this when the getphnum() is called one time i wnat to get firts index value(ie index 0 ph number)ie MPN arraylist.ANd when next time when getphnum () is called i want to get index 1 value from arraylist MPN.(ie the same arraylist from which i call my first array index value).. can somebody help meeeeeeeeeeee :| :|

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

        merryjoy000 wrote:

        in this when the getphnum() is called one time i wnat to get firts index value(ie index 0 ph number)ie MPN arraylist.ANd when next time when getphnum () is called i want to get index 1 value from arraylist MPN

        Do you mean a counter? If yes, use "static“ for z var.

        :) I Love KongFu~

        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