Concatenating ArrayLists in C#
How can we concatenate two arraylists in C#? I have tried it but I am not able to find the exact solution and always end up with some or the other error. Please help. This is my second language which I am learning. I have earlier studied HTML (Hyper text Mark-up Language). But it is not at all helpul for me in C#. I am confused and need a solution.
Re: Concatenating ArrayLists in C#
For me also my first programming language was C-Sharp. And it was not at all easy to grasp all the concepts. My advise to all is to first get yourself educated with C++ and Java. Here is an example for concatenating ArrayLists in C-Sharp.
Code:
System.Collections.ArrayList arrl1 = new System.Collections.ArrayList();
System.Collections.ArrayList arrl2 = new System.Collections.ArrayList();
arrl1.Add("5");
arrl1.Add("10");
arrl2.Add("15");
arrl2.Add("20");
To concatenate we will make use of:
Code:
arrl1.AddRange(arrl2);
Re: Concatenating ArrayLists in C#
It is very simple first declare the two array lists. Input their respective data. Once done, we can then make use of .AddRange() method of C-Sharp to concatenate the two array lists. Thus, to concatenate arraylists in C-Sharp we make use of the .AddRange() method which simply joints one arraylist to another.
Re: Concatenating ArrayLists in C#
Code:
Dim list1 As New ArrayList() // declaring first arraylist
list1.Add("This")
list1.Add("is")
list1.Add("to")
list1.Add("concatenate")
Dim list2 As New ArrayList() // declaring second arraylist
list2.Add("Arraylist")
list2.Add("in")
list2.Add("C-Sharp")
list1.AddRange(list2) // concatenate the two array lists
In Csharp we can easily use a .AddRange() to concatenate the two array lists. Csharp helps the developer/ programmer to easily build a .Net framework application. Most of the .Net application are coded in Csharp.