您好,欢迎访问一九零五行业门户网

C# 中的集合类是什么?

集合类具有各种用途,例如动态分配内存给元素,根据索引访问项目列表等。
以下是collections中的类:
序号类别和描述和用法
1 arraylist它表示一个可以单独索引的对象的有序集合。
2 hashtable它使用键来访问集合中的元素。
3 sortedlist它使用键和索引来访问列表中的项。
4 stack它表示一个后进先出的对象集合。
5 queue它表示一个先进先出的对象集合。
6 bitarray它表示使用值1和0的二进制表示的数组。
让我们看一个c#中bitarray类的例子:
例子 在线演示
using system;using system.collections;namespace collectionsapplication { class program { static void main(string[] args) { //creating two bit arrays of size 8 bitarray ba1 = new bitarray(8); bitarray ba2 = new bitarray(8); byte[] a = { 60 }; byte[] b = { 13 }; //storing the values 60, and 13 into the bit arrays ba1 = new bitarray(a); ba2 = new bitarray(b); //content of ba1 console.writeline("bit array ba1: 60"); for (int i = 0; i < ba1.count; i++) { console.write("{0, -6} ", ba1[i]); } console.writeline(); //content of ba2 console.writeline("bit array ba2: 13"); for (int i = 0; i < ba2.count; i++) { console.write("{0, -6} ", ba2[i]); } console.writeline(); bitarray ba3 = new bitarray(8); ba3 = ba1.and(ba2); //content of ba3 console.writeline("bit array ba3 after and operation: 12"); for (int i = 0; i < ba3.count; i++) { console.write("{0, -6} ", ba3[i]); } console.writeline(); ba3 = ba1.or(ba2); //content of ba3 console.writeline("bit array ba3 after or operation: 61"); for (int i = 0; i < ba3.count; i++) { console.write("{0, -6} ", ba3[i]); } console.writeline(); console.readkey(); } }}
输出bit array ba1: 60false false true true true true false falsebit array ba2: 13true false true true false false false falsebit array ba3 after and operation: 12false false true true false false false falsebit array ba3 after or operation: 61true false true true false false false false
以上就是c# 中的集合类是什么?的详细内容。
其它类似信息

推荐信息