5 Replies - 1656 Views - Last Post: 17 February 2010 - 04:21 AM Rate Topic: -----

#1 systemerror   User is offline

  • D.I.C Head

Reputation: -19
  • View blog
  • Posts: 205
  • Joined: 15-August 09

C# Arraylist Back And Forth

Posted 12 February 2010 - 11:41 PM

This is my code setup

        private void button1_Click(object sender, EventArgs e)
        {
            // Create a new ArrayList
            ArrayList numbers = new ArrayList();
            // Add some numbers to the list
            numbers.Add(7);
            numbers.Add(21);
            // Get the numbers out of the list
            // Notice a cast is required because
            // ArrayList only contain objects (untyped)
            // This also performs an unboxing operation
            int numA = (int)numbers[0];
            int numB = (int)numbers[1];
        }


Thats my control memory list, but i don't know how to go back and forth with it

Is This A Good Question/Topic? 0
  • +

Replies To: C# Arraylist Back And Forth

#2 Momerath   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1021
  • View blog
  • Posts: 2,463
  • Joined: 04-October 09

Re: C# Arraylist Back And Forth

Posted 12 February 2010 - 11:49 PM

What are you trying to do with the ArrayList? You'd also be better off using the List<>, as you won't have to cast.
Was This Post Helpful? 1
  • +
  • -

#3 systemerror   User is offline

  • D.I.C Head

Reputation: -19
  • View blog
  • Posts: 205
  • Joined: 15-August 09

Re: C# Arraylist Back And Forth

Posted 13 February 2010 - 03:14 AM

View Postsystemerror, on 12 February 2010 - 10:41 PM, said:

This is my code setup

        private void button1_Click(object sender, EventArgs e)
        {
            // Create a new ArrayList
            ArrayList numbers = new ArrayList();
            // Add some numbers to the list
            numbers.Add(7);
            numbers.Add(21);
            // Get the numbers out of the list
            // Notice a cast is required because
            // ArrayList only contain objects (untyped)
            // This also performs an unboxing operation
            int numA = (int)numbers[0];
            int numB = (int)numbers[1];
        }


Thats my control memory list, but i don't know how to go back and forth with it


Well I have a colour green on backgound at the start, and I want it to remember that coz when i press the button the colour wiull change to blue, and i want to be able to go back and forth through that memory list
Was This Post Helpful? 0
  • +
  • -

#4 Core   User is offline

  • D.I.C Lover
  • member icon

Reputation: 785
  • View blog
  • Posts: 5,101
  • Joined: 08-December 08

Re: C# Arraylist Back And Forth

Posted 13 February 2010 - 03:26 AM

If you are working with an array of items and you know their type, then I would recommend wither using an array (for example, int[] - but you will need to know the size of it) or implement a list (List<int>) of integers.

If you choose to work with arrays, you will work with the standard assignment/reading procedure. For example:

myArray[9] = 0;

int readValue = myArray[9];



With a List<int> you will do it this way:

List<int> listOfInt = new List<int>();
listOfInt.Add(1);

int readValue = listOfInt[0];


Was This Post Helpful? 1
  • +
  • -

#5 systemerror   User is offline

  • D.I.C Head

Reputation: -19
  • View blog
  • Posts: 205
  • Joined: 15-August 09

Re: C# Arraylist Back And Forth

Posted 13 February 2010 - 05:36 PM

View Postsystemerror, on 13 February 2010 - 02:14 AM, said:

View Postsystemerror, on 12 February 2010 - 10:41 PM, said:

This is my code setup

        private void button1_Click(object sender, EventArgs e)
        {
            // Create a new ArrayList
            ArrayList numbers = new ArrayList();
            // Add some numbers to the list
            numbers.Add(7);
            numbers.Add(21);
            // Get the numbers out of the list
            // Notice a cast is required because
            // ArrayList only contain objects (untyped)
            // This also performs an unboxing operation
            int numA = (int)numbers[0];
            int numB = (int)numbers[1];
        }


Thats my control memory list, but i don't know how to go back and forth with it


Well I have a colour green on backgound at the start, and I want it to remember that coz when i press the button the colour wiull change to blue, and i want to be able to go back and forth through that memory list



I'll use int<> it makes more scene, but it don't show how you can use them
Was This Post Helpful? 0
  • +
  • -

#6 Adkins   User is offline

  • D.I.C Addict
  • member icon

Reputation: 66
  • View blog
  • Posts: 560
  • Joined: 27-October 09

Re: C# Arraylist Back And Forth

Posted 17 February 2010 - 04:21 AM

I am completely not understanding the question. If you wanna switch back and forth between them, why not just use a simple if statement.
if (numA)
{
    numB
}
else
{
    numA
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1