AddRange And InsertRange Methods In ArrayList
AddRange and InsertRange method provides a good deals with the Arrays. Both are the methods of ArrayList.
--------------------------------------------------------------------------------------------------------
using System;
using System.Collections;
class AddRangeAndInsertRangeWithArrayList
{
static void Main()
{
int[] arr = {23,4,45,56,78};
int[] arr1 = {1,2,3};
ArrayList arrlist = new ArrayList();
Console.WriteLine("----------------Add Method---------");
arrlist.Add(8);
arrlist.Add(9);
foreach (int v in arrlist)
{
Console.Write(v + "\t" );
}
Console.WriteLine();
Console.WriteLine("\n----------------Add Range Method---------");
arrlist.AddRange(arr);
foreach (int v in arrlist)
{
Console.Write(v + "\t" );
}
Console.WriteLine();
Console.WriteLine("\n----------------Insert Range Method---------");
arrlist.InsertRange(0, arr1);
foreach (int v in arrlist)
{
Console.Write(v + "\t");
}
}
}
--------------------------------------------------------------------------------------------------------
using System;
using System.Collections;
class AddRangeAndInsertRangeWithArrayList
{
static void Main()
{
int[] arr = {23,4,45,56,78};
int[] arr1 = {1,2,3};
ArrayList arrlist = new ArrayList();
Console.WriteLine("----------------Add Method---------");
arrlist.Add(8);
arrlist.Add(9);
foreach (int v in arrlist)
{
Console.Write(v + "\t" );
}
Console.WriteLine();
Console.WriteLine("\n----------------Add Range Method---------");
arrlist.AddRange(arr);
foreach (int v in arrlist)
{
Console.Write(v + "\t" );
}
Console.WriteLine();
Console.WriteLine("\n----------------Insert Range Method---------");
arrlist.InsertRange(0, arr1);
foreach (int v in arrlist)
{
Console.Write(v + "\t");
}
}
}
--------------------------------------------------------------------------------------------------------
AddRange And InsertRange Methods In ArrayList
Reviewed by Baljeet Singh
on
00:35
Rating:
No comments: