How to use Arraylist in C# Using Asp.Net

Arraylist in C# Using Asp.Net 

ArrayList is the one of the easiest and flexible  data structure in the c# . Arraylist size is dynamically increased if user required . user create various datatypes int,string etc by arraylist.


ArrayList arrlist = new ArrayList();


ArrayList property is having many types Capacity,Count,Clear,Contrains,IndexOf,Remove,Sort,Reverse,Insert,Range etc...

Code:

        ArrayList lia = new ArrayList();
        lia.Add("Dotnet");
        lia.Add("Drizzles");
        lia.Add("blogspot.in");

        Response.Write("Result Is == "+ lia.IndexOf("Dotnet"));

Check Indexof from arraylist  condition true  Index Position 0

Code:

ArrayList lia = new ArrayList();
        lia.Add("Dotnet");
        lia.Add("Drizzles");
        lia.Add("blogspot.in");

        Response.Write("Result Is == "+ lia.IndexOf("Dotne"));

Check Indexof from arraylist  condition False  Index Position -1

Code:

        ArrayList lia = new ArrayList();
        lia.Add("Dotnet");
        lia.Add("Drizzles");
        lia.Add("blogspot.in");

        Response.Write("Result Is == "+ lia.Count);

 Arraylist  Count the total values (3)


Code:

ArrayList lia = new ArrayList();
        lia.Add("Dotnet");
        lia.Add("Drizzles");
        lia.Add("blogspot.in");

        Response.Write("Result Is == "+ lia.Contains("Drizzles"));


Check Contains Drizzles from arraylist  Result is True

Code:

ArrayList lia = new ArrayList();
        lia.Add("Dotnet");
        lia.Add("Drizzles");
        lia.Add("blogspot.in");

        Response.Write("Result Is == "+ lia.Contains("Drizz"));

Check Contains Drizz from arraylist  Result is False

Code:

 ArrayList lia = new ArrayList();
        lia.Add("blogspot.in");
        lia.Add("Dotnet");
        lia.Add("Drizzles");

        lia.Sort();
        foreach (string s in lia)
        {
            Response.Write(s.ToString());
        }


Sort the  Arraylist  Result is Ascending order

Code:

 ArrayList lia = new ArrayList();
        lia.Add("blogspot.in");
        lia.Add("Dotnet");
        lia.Add("Drizzles");

        lia.Reverse();
        foreach (string s in lia)
        {
            Response.Write(s.ToString());
        }


Reverse the  Arraylist  Result is Descending order


Code:

ArrayList lia = new ArrayList();
        lia.Add("Dotnet");
        lia.Add("Drizzles");
        lia.Add("blogspot.in");

        lia.RemoveAt(2);
        foreach (string s in lia)
        {
            Response.Write(s.ToString());
        }

Remove the  Arraylist  2 index


Code:

  ArrayList lia = new ArrayList();
        lia.Add("Dotnet");
        lia.Add("Drizzles");
        lia.Add("blogspot.in");

        //GetRange(start index , count)
        ArrayList range = lia.GetRange(1,2);
       
        foreach (string s in range)
        {
            Response.Write(s.ToString());
        }



Get Range From  Arraylist  Range(1,2) - Index start 1, count 2




Code:

ArrayList lia = new ArrayList();
        lia.Add("Dotnet");
        lia.Add("Drizzles");
        lia.Add("blogspot.in");

        lia.Insert(2, ".");

        foreach (string s in lia)
        {
            Response.Write(s.ToString());
        }


Insert to the  Arraylist  in . Insert(2,".") - 2 is index , . is insert value


Code:

 ArrayList lia = new ArrayList();
        lia.Add("Dotnet");
        lia.Add("Drizzles");
        lia.Add("blogspot.in");

       //LastIndexOf(object value,Index,count)
       Response.Write(lia.LastIndexOf("Dotnet", 0, 0) + "<br/>");       
       Response.Write(lia.LastIndexOf("Dotnet",0,1));
      
LastIndexOf search object value,index,count from Arraylist




0 comments:

Post a Comment