how to add arrays to Ilist

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jitendrapatil2006@gmail.com

    how to add arrays to Ilist

    hey friends i am new to C# lang. can anybody tell me how to add arrays
    to Ilist and how to get the values from the list( means) how to
    traverse the list plz help me...
  • Marc Gravell

    #2
    Re: how to add arrays to Ilist

    Do you want to add the array to a list, or do you want to add the
    *content* of the array to the list; i.e. if I have:

    // array
    int[] myInts = {1,2,3};

    if we add that to an empty list, do you want 1 item in the list (which
    is an array), or do you want 3 items in the list (the integers)?

    I would recommend using generics here, such as List<T>; for example:

    List<intmyList = new List<int>();
    // ...
    myList.AddRange (myInts);

    For traversing the list, "foreach" is your friend, as it works for any
    IEnumerable[/<T>] instance:

    foreach (int i in myList)
    {
    Console.WriteLi ne(i);
    }

    Note you can also use "foreach" over myInts; the advantage of a list
    is that you can add/remove items (arrays are fixed-size).

    Marc

    Comment

    Working...