57.ArrayList in C#

 using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Collections;

namespace arraylist

{

    class Program

    {

        static void Main(string[] args)

        {

            ArrayList arr1 = new ArrayList();


            arr1.Add("Milan");

            arr1.Add("Krunal");

            arr1.Add("Divya");

            arr1.Add("Riya");

            arr1.Add("Divi");


            foreach (String val in arr1)

            {

                Console.WriteLine(val);

            }

            Stack s1 = new Stack();

            s1.Push(5);

            s1.Push(15);

            s1.Push(25);

            s1.Push(35);

            s1.Push(45);

            Console.WriteLine("====  After Add StackObject into arraylist ====");

            arr1.AddRange(s1);


            foreach(object val in arr1)

            {

                Console.WriteLine(val);

            }

            ArrayList arr2 = new ArrayList();


            arr2.Add("Milan2");

            arr2.Add("Krunal2");

            arr2.Add("Divya2");

            arr2.Add("Riya2");

            arr2.Add("Divi2");


            int pos = arr2.BinarySearch("Divi2");

           // Console.WriteLine("======= After Search Element Position is =========");

            Console.WriteLine("Position is : " + pos.ToString());

            arr2.Insert(3, "Devanshi");

            Console.WriteLine("====== AFter Insert Method ======== ");

            foreach (object val in arr2)

            {

                Console.WriteLine(val);

            }

            arr2.InsertRange(3, s1);

            Console.WriteLine("======== After Insert Range Method ===== ");

            foreach (object val in arr2)

            {

                Console.WriteLine(val);

            }

            arr2.Remove("Divi2");

            Console.WriteLine("====== AFter Remove Method ======== ");

            foreach (object val in arr2)

            {

                Console.WriteLine(val);

            }

            arr2.RemoveAt(2);

            Console.WriteLine("====== AFter Remove At Method ======== ");

            foreach (object val in arr2)

            {

                Console.WriteLine(val);

            }

            arr2.RemoveRange(2, 4);

            Console.WriteLine("======== AFter Remove Range Method =====");

            foreach (object val in arr2)

            {

                Console.WriteLine(val);

            }

            Console.WriteLine("Contains() Result is :" + arr2.Contains("ABC"));

            Console.WriteLine("Size of Array List is :" + arr2.Capacity);

            arr2.Capacity = 50;

            Console.WriteLine("Now Size of Array List is :" + arr2.Capacity);

            arr2.TrimToSize();

            Console.WriteLine("After Trim the Size Of Array List is :" + arr2.Capacity);

            Console.WriteLine("Total Element in ArrayList is :" + arr2.Count);

            Console.Read();

        }

    }

}

OUTPUT:
Milan
Krunal
Divya
Riya
Divi
====  After Add StackObject into arraylist ====
Milan
Krunal
Divya
Riya
Divi
45
35
25
15
5
Position is : -1
====== AFter Insert Method ========
Milan2
Krunal2
Divya2
Devanshi
Riya2
Divi2
======== After Insert Range Method =====
Milan2
Krunal2
Divya2
45
35
25
15
5
Devanshi
Riya2
Divi2
====== AFter Remove Method ========
Milan2
Krunal2
Divya2
45
35
25
15
5
Devanshi
Riya2
====== AFter Remove At Method ========
Milan2
Krunal2
45
35
25
15
5
Devanshi
Riya2
======== AFter Remove Range Method =====
Milan2
Krunal2
5
Devanshi
Riya2
Contains() Result is :False
Size of Array List is :16
Now Size of Array List is :50
After Trim the Size Of Array List is :5
Total Element in ArrayList is :5

Comments

Popular posts from this blog

7.Write a program to read a list containing item name, item code and cost interactively and produce a three-column output as shown below. NAME CODE COST Turbo C++ 1001 250.95 C Primer 905 95.70 ------------- ------- ---------- ------------- ------- ---------- Note that the name and code are left-justified and the cost is right-justified with a precision of two digits. Trailing zeros are shown.

Quetion 6 : Consider the "in-order-issue/in-order-completion" execution sequence shown in f In Figure Decode OWE Execute 12 12 12 14 16 13 16 13 15 15 16 Write 024/06/02 11 3 4 11 12 13 13 N 15 16 a. Identify the most likely reason why I could not enter the execute fourth cycle. stage until the [2] b. Will "in-order issue/out-of-order completion" or "out-of-order issue/out-of-order completion" fix this? If so, which? Explain

8.odd and even number using if else.