精品ppt课件清华大学原版c#学习资料第10章集合止.pptVIP

  • 12
  • 0
  • 约7.72千字
  • 约 19页
  • 2017-10-07 发布于湖北
  • 举报

精品ppt课件清华大学原版c#学习资料第10章集合止.ppt

精品ppt课件清华大学原版c#学习资料第10章集合止.ppt

集合 目标 数组列表、哈希表、堆栈集合的用法 体验 首先产生一个包含有12个随机数的数组,然后分别计算出数组中的最大值、最小值。最后程序将显示整个随机数数组。随机数的范围是1—100之间。 集合 类名称 说 明 ArrayList 动态数组 BitArray 位数组 Hashtable 关键字和值的查找表 Queue 先进/先出(FIFO)的元素集合 SortedList 元素的有序列表 Stack 后进/先出(LIFO)的元素集合 System.Collections命名空间 数组列表集合-ArrayList 类似一维数组 数组列表是动态数组 可以存放任何对象 常用方法: 增加元素-Add 插入元素-Insert 删除元素-Remove ArrayList示例 ArrayList myAL = new ArrayList(); myAL.Add(Hello); myAL.Add(World); myAL.Add(!); Console.WriteLine(myAL); Console.WriteLine( Count: {0}, myAL.Count); Console.WriteLine( Capacity: {0}, myAL.Capacity); Console.Write( Values:); PrintValues(myAL); public static void PrintValues(IEnumerable myList) { foreach (Object obj in myList) Console.Write( {0}, obj); Console.WriteLine(); } 位数组集合-BitArray BitArray集合是位值(位值是1和0)的组合体 BitArray位集合是其元素为位标志的集合 每一元素都是一位,而不是一个对象 BitArray容量始终与计数相同 提供位运算方法,例如And、Or、Xor、Not和SetAll 等 1 0 0 1 1 1 0 Length BitArray flags = new BitArray(7) flags.Set(0,true); flags.Set(1,false); … bool IsMarry = flags.Get(3); 是否结婚 性别(男女) BitArray-示例 using System; using System.Collections; public class SamplesBitArray { public static void Main() { BitArray myBA1 = new BitArray(5); BitArray myBA2 = new BitArray(5); myBA1[0] = myBA1[1] = false; myBA1[2] = myBA1[3] = true; myBA2[0] = myBA2[2] = false; myBA2[1] = myBA2[3] = true; myBA2[1] = myBA2[4] = true; Console.WriteLine(初始值:); Console.Write(myBA1:); PrintValues(myBA1, 8); Console.Write(myBA2:); PrintValues(myBA2, 8); Console.WriteLine(); Console.WriteLine(结果:); Console.Write(位与操作AND:); PrintValues(myBA1.And(myBA2), 8); Console.WriteLine(); Console.WriteLine(After AND); Console.Write(myBA1:); PrintValues(myBA1, 8); Console.Write(myBA2:); PrintValues(myBA2, 8); Console.WriteLine(); try { BitA

文档评论(0)

1亿VIP精品文档

相关文档