How to use HASH TABLE,ARRAYLIST in c# explain with example? Contact Author
Answer :
The ArrayList object is a collection of items containing a single data value.
Items are added to the ArrayList with the Add() method. The following code creates a new ArrayList object named mycountries and four items are added: <script runat="server"> Sub Page_Load if Not Page.IsPostBack then dim mycountries=New ArrayList mycountries.Add("Norway") mycountries.Add("Sweden") mycountries.Add("France") mycountries.Add("Italy") end if end sub </script> U can sort it alphabetically mycountries.Sort() By default, an ArrayList object contains 16 entries. An ArrayList can be sized to its final size with the TrimToSize() method: mycountries.TrimToSize() For reversing mycountries.Reverse() With DB rb.DataSource=mycountries rb.DataBind()
The Hashtable object contains items in key/value pairs. The keys are used as indexes, and very quick searches can be made for values by searching through their keys.
Items are added to the Hashtable with the Add() method.
The following code creates a Hashtable named mycountries and four elements are added:
<script runat="server"> Sub Page_Load if Not Page.IsPostBack then dim mycountries=New Hashtable mycountries.Add("N","Norway") mycountries.Add("S","Sweden") mycountries.Add("F","France") mycountries.Add("I","Italy") end if end sub </script>
---- <script runat="server"> sub Page_Load if Not Page.IsPostBack then dim mycountries=New Hashtable mycountries.Add("N","Norway") mycountries.Add("S","Sweden") mycountries.Add("F","France") mycountries.Add("I","Italy") rb.DataSource=mycountries rb.DataValueField="Key" rb.DataTextField="Value" rb.DataBind() end if end sub </script><html> <body><form runat="server"> <asp:RadioButtonList id="rb" runat="server" AutoPostBack="True" /></form></body> </html>