Collection libraries: in c#

 

 

# Collection libraries:-

1. Collection libraries is providing data management concept .

2.There are following collection method used in c#.

a.Array list

b.                  Stack

c. Hash table

d.                  Shortedlist

# loop catagories:-

1.Variable loop- while do for

2.Object loop – foreach loop we cant use relational operator.

Syntax:- foreach(variable  in object )

{

}

 

A.                  Array List :-

Prog

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Collections;

 

 

namespace progarraylist

{

    class Program

    {

        static void Main(string[] args)

        {

            ArrayList a1 = new ArrayList();

            // insert element i array list

            a1.Add(20);

            a1.Add(30);

            a1.Add(10);

            a1.Add(9);

            // display count of array list

 

            Console.WriteLine(a1.Count);

            // display array list element

 

            foreach (int k in a1)

            {

                Console.WriteLine(k);

 

            }

            // arrange array list element

            a1.Sort();

            Console.WriteLine("The sorted array are printed below");

            foreach(int k in a1)

            {

                Console.WriteLine(k);

            }

            // removing array list element

            a1.Remove(9);

            // after removing element

            Console.WriteLine("after removing");

            foreach(int k in a1)

            {

                Console.WriteLine(k);

 

            }

           

            Console.ReadKey();

        }

    }

}

 

# Stack – It is used to arranged the element in LIFO .

# Stack method

1.Push

2.Pop – Remove only one element

Prog-

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Collections;

 

namespace progstack

{

    class Program

    {

        static void Main(string[] args)

        {

            Stack s1 = new Stack();

            s1.Push('A');

            s1.Push('B');

            s1.Push('C');

            s1.Push('D');

 

            foreach(char k in s1 )

            {

                Console.WriteLine(k);

 

            }

            s1.Pop();

            Console.WriteLine("After removing");

            foreach (char k in s1)

            {

                Console.WriteLine(k);

 

            }

            Console.ReadKey();

 

        }

    }

}

 

Task given in whatapp. Total 2 task.

 

Comments

Popular posts from this blog

ViewState for state management

Store procedure Data Base handling (procedure_insert).

Database joining