C # Array: [], List, Array, and ArrayList applications,
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 a structure
Int [] arr = new int [] {1, 2, 3 };
Response. Write (arr [0]); // 1
Change (arr );
Response. Write (arr [0]); // 2
// The namespace of the List 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 Array is System
Array array = Array. CreateInstance (System. Type. GetType ("System. Int32"), 3); // Array is an abstract class and cannot be created using 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 namespace of ArrayList 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. SetValue (int) array. GetValue (I) * 2, I); // type conversion required
}
}
Private void Change (ArrayList arrayList)
{
For (int I = 0; I <arrayList. Count; I ++) // use Count
{
ArrayList [I] = (int) arrayList [I] * 2; // type conversion required
}
}
}
[] Is for a specific type and fixed length.
List is for a specific type and any length.
Array is of any type and fixed length.
ArrayList is for any type and length.
Array and ArrayList implement any type by storing objects. Therefore, they must be converted during use.
From: http://www.111cn.net/net/160/40651.htm
In the C language, what is the symbol (->) and how to use it?
This is a symbol in the struct pointer. Write a program to explain it, for example:
# Include <stdio. h>
Struct STU // define a struct
{
Int num;
} Stu;
Int main ()
{
Struct STU * p; // defines a struct pointer.
P = stu; // p points to the struct variable stu.
Stu. num = 100; // attaches an initial value to the struct member num.
Printf ("% d", p-> num); // output the num value in stu
Return;
}
As you can see, the-> method is to reference the variable in the struct !!
Format: p-> struct member (such as p-> num)
The function is equivalent to stu. num or (* p). num.
I don't know. You don't understand, and don't understand call me. O (∩ _ ∩) O ~
Hope to adopt it.
In the C language, what is the symbol (->) and how to use it?
This is a symbol in the struct pointer. Write a program to explain it, for example:
# Include <stdio. h>
Struct STU // define a struct
{
Int num;
} Stu;
Int main ()
{
Struct STU * p; // defines a struct pointer.
P = stu; // p points to the struct variable stu.
Stu. num = 100; // attaches an initial value to the struct member num.
Printf ("% d", p-> num); // output the num value in stu
Return;
}
As you can see, the-> method is to reference the variable in the struct !!
Format: p-> struct member (such as p-> num)
The function is equivalent to stu. num or (* p). num.
I don't know. You don't understand, and don't understand call me. O (∩ _ ∩) O ~
Hope to adopt it.