您的位置:首页 > 编程语言 > C#

【C#学习笔记】List容器使用

2013-10-06 13:47 253 查看
using System;
using System.Collections.Generic;

namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
List<int> a = new List<int>();
a.Add(10);          //顺序增加
a.Add(34);
a.Insert(2, 1);     //第2个位置插入1

foreach (int i in a)
Console.Write(i + " ");

Console.WriteLine();

a.Sort();           //从小到大排序
for (int i = 0; i < a.Count;i++ )
Console.Write(a[i] + " ");

a.Contains(10); //是否包含10
a.IndexOf(1);  //返回元素1的下标

a.Remove(1);    //删除1这个元素
a.RemoveAt(0);  //删除位置在0的元素

a.Clear();
Console.Read();
}
}
}


类似于C++中vector。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐