C # collection class (1): arraylist

Source: Internet
Author: User
The system. Collections namespace contains interfaces and classes that define a set of objects (such as lists, queues, bit arrays, hash tables, and dictionaries.
System. collections. the generic namespace contains interfaces and classes that define a generic set. A generic set allows you to create a strongly typed set. It provides better type security and performance than a non-generic strong set.
The system. Collections. Specialized namespace contains specialized and strong collections, such as list dictionaries for links, bitvectors, and collections that only contain strings.

Arraylist Class: use an array that can be dynamically increased as needed. Using System;
Using System. Collections. Generic;
Using System. text;
Using System. collections;
Namespace Leleapplication1
{
Class Program
{
Static   Void Main ( String [] ARGs)
{
Arraylist al
=   New Arraylist ();
Al. Add (
100 ); // Single add
Foreach ( Int Number In   New   Int [ 6 ] {9,3,7,2,4,8} )
{
Al. Add (number );
//Add group method 1
}

Int [] Number2 =   New   Int [ 2 ] {11,12} ;
Al. addrange (number2 );
// Method 2
Al. Remove ( 3 ); // Remove 3
Al. removeat ( 3 ); // Remove 3rd
Arraylist al =   New Arraylist (Al. getrange ( 1 , 3 )); // The new arraylist takes only one copy of the old arraylist.


Console. writeline (
" Method 1: " );
Foreach ( Int I In Al) // Do not force conversion
{
Console. writeline (I );
//Traversal method 1
}


Console. writeline (
" Method 2: " );
For ( Int I =   0 ; I < Al2.count; I ++ ) // Array is length
{
Int Number = ( Int ) Al 2 [I]; // Mandatory Conversion
Console. writeline (number ); // Method 2

}

}

}

}

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.