As an array of collections: The following is a simple example:
<% @Page language= "C #"%>
<script runat= "Server" language= "C #" >
void Page_Load ()
{
string[] Animalarray = new String[5]
{"Dog", "Cat", "Elephant", "Lion", "Cat"};
MyLabel.Text = Animalarray.getvalue (2). ToString () + "<font color=red>" +array.indexof (Animalarray, "Cat") + "</font>";
}
</script>
<asp:label id= "MyLabel" runat= "Server"/>
The output of this program is clearly: Elephant.
The following is a program that is traversed somewhere in an array:
<% @Page language= "C #"%>
<script runat= "Server" language= "C #" >
void Page_Load ()
{
int intcounter =-1;
string[] Animalarray = new String[5]
{"Dog", "Cat", "Elephant", "Lion", "Cat"};
Todo
{
intcounter = Array.indexof (Animalarray, "Cat", intcounter+1);
mytext.innerhtml + + "animalarray[" + intcounter + "]<br/>";
while (intcounter!= array.lastindexof (Animalarray, "Cat"));
}
</script>
The string "Cat" occurs in the following elements:
<br/>
<div id= "MyText" runat= "Server"/>
Reverses the order of elements in an array: Array.reverse (Array1);
Sort the elements: Array.Sort (Array1);
Data binding:
A common feature of a collection is that you can specify a collection as a data source by adding a pair of statements.
As in the previous program:
Definition: Arraylins myarraylist=new ArrayList ();
Each new item will automatically be added to the end of the document!
The previous program can be modified like this:
Two ways to add values:
Myhashtable.add ([UK], "Hongkong");
OR
myhashtable[uk]= "Hongkong";
Hashtable.add () takes two parameters, one for keys and one for values. Both belong to the type object. The value passed for the key is an integer, so it must be boxed to be passed as an object. The value passed for the value is a string, which is a reference type, so no boxing of strings. Get one point for each correct one.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.