Printing all elements in Array

Hi,

Is there any function (inbuilt) which print all the elements of the Array. 

I need to print or see what an array contains and the Index/Key of it as well. I can do it by using foreach and it will display the value of each element, but is there any  single function in Vb.Net that took the Array of any kind and print the Elements of it with corresponding Key/Index value.

Thanks


Answer this question

Printing all elements in Array

  • Doug2005

    Hi,

    Thanks for the Information...

    that Loop function is what I am currently using.

    Also can you suggest a way like in Recordset ad Session variable in ASP.NEt we can define a name to a index of an array can we do the same with our own Array 

    like in general if we do 

    s[0]="value"
    s[1]="value2"

    Now I want this

    s['index1']="value"
    s['index2']="value"

    Is it possible 

    Thanks

  • halflife28

    There's no such function, because that would couple the Array class to some sort of UI (Console, Windows Form or whatever).

    If you need the index, you can't use foreach. Instead, use a regular for-loop:
    private void PrintArray(string[] s)
    {
        for (int i=0; i<s.Length; i++)
        {
            Console.WriteLine("{0} {1}", i, s[i]);
        }
    }

  • KevinGW

    You could use a System.Collections.HashTable, but that only takes one name. While it's possible to use a string and an integer as the indexer, they refer to different items.
  • Printing all elements in Array