C # Array of [], List, array, ArrayList applications

Source: Internet
Author: User

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Collections;

public partial class _default:system.web.ui.page
{
protected void Page_Load (object sender, EventArgs e)
{
System.Int32 is the structure
int[] arr = new int[] {1, 2, 3};
Response.Write (Arr[0]); 1
Change (arr);
Response.Write (Arr[0]); 2

The List namespace is System.Collections.Generic
list<int> list = new list<int> ();
List. ADD (1);
List. ADD (2);
List. ADD (3);
Response.Write (List[0]); 1
Change (list);
Response.Write (List[0]); 2

The namespace of the Array is the System
Array array = array.createinstance (System.Type.GetType ("System.Int32"), 3); Array is an abstract class and cannot be created using the new array.
Array. SetValue (1, 0);
Array. SetValue (2, 1);
Array. SetValue (3, 2);
Response.Write (Array. GetValue (0)); 1
Change (array);
Response.Write (Array. GetValue (0)); 2

The ArrayList namespace is system.collectio (www.111cn.net) NS
ArrayList ArrayList = new ArrayList (3);
Arraylist.add (1);
Arraylist.add (2);
Arraylist.add (3);
Response.Write (Arraylist[0]); 1
Change (arrayList);
Response.Write (Arraylist[0]); 2
}

private void Change (int[] arr)
{
for (int i = 0; i < arr. Length; i++)
{
Arr[i] *= 2;
}
}

private void Change (list<int> List)
{
for (int i = 0; i < list. Count; i++)//Use Count
{
List[i] *= 2;
}
}


private void Change (array array)
{
for (int i = 0; i < array. Length; i++)//Use Length
{
Array. An array of SetValue ((int). GetValue (i) * 2, I); Type conversions Required
}
}

private void Change (ArrayList ArrayList)
{
for (int i = 0; i < Arraylist.count; i++)//Use Count
{
Arraylist[i] = (int) arraylist[i] * 2; Type conversions Required
}
}
}

[] is for a specific type, fixed length.

List is for a specific type, any length.

The Array is for any type, fixed length.

The ArrayList is for any type, any length.

Arrays and ArrayList are implemented by storing objects of any type, so they are used to convert
From:http://www.111cn.net/net/160/40651.htm

C # Array of [], List, array, ArrayList applications

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.