how to add arrays to Ilist

  • Thread starter Thread starter jitendrapatil2006
  • Start date Start date
J

jitendrapatil2006

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...
 
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<int> myList = 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.WriteLine(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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

IList<T> and IList 6
Sorting IList<T> *in place* 9
List. Add, Remove. 1
Excel to IList<Object> and Back 1
Adding Lists to Lists 7
Array question 2
simple generics IList question 1
About Array and IList 2

Back
Top