Question

I'm trying to figure out what sort of information these messages contain that are being streamed via OSC. The messages are being stored to an ArrayList. Here is the code:

public void OSCMessageReceived(OSC.NET.OSCMessage message){ 
        string address = message.Address;
        ArrayList args = message.Values;
}

How do I loop through the values of the arrayList args to output its contents?

Was it helpful?

Solution

you can try with this code

foreach(var item in args )
{
  Console.WriteLine(item);
}

OTHER TIPS

You can use a simple for loop:

for (i = 0; i < args.Count; i++)
{
    Console.WriteLine(args[i].ToString());
}

Check out this link here for more info on the C# ArrayList object.

ArrayList al = new ArrayList(new string[] { "a", "b", "c", "d", "e" });
foreach (var item in al)
{
    Console.WriteLine(item);
}

You can also use a for loop.

for (int i = 0; i < al.Count; ++i)
{
    Console.WriteLine(al[i]);
}

Unless you know the type of objects in the ArrayList, your only option is to call the ToString() method on each item.

If you do know the type of objects, you can cast them to the appropriate type and then to print the content in a more intelligent way.

Both foreach() and for(int i = 0;...) scroll through all entries of the ArrayList. However it seems that foreach() scrolls through them in the order in which they were added to the ArrayList. With for(int i = 0;...) I observed (Visual Studio 2005) that this is not necessarily true. I experienced in one case that when the objects added to the ArrayList were simple int's it was the case. However when the added objects were of a complex class type the scroll order no longer corresponded to the order in which they had been added to the ArrayList.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top