//雜湊表
hashtable student = new hashtable();
for (int i = 0; i < 10; i++)
}//根據鍵移除元素
student.remove("sk3");
foreach (dictionaryentry element in student)
//學生的id:sk9,學生的姓名:sv9
//學生的id:sk8,學生的姓名:sv8
//學生的id:sk5,學生的姓名:sv5
//學生的id:sk6,學生的姓名:sv6
//學生的id:sk7,學生的姓名:sv7
//學生的id:sk4,學生的姓名:sv4
//學生的id:sk1,學生的姓名:sv1
//學生的id:sk0,學生的姓名:sv0
//學生的id:sk2,學生的姓名:sv2
arraylist arrlist = new arraylist();
arrlist.add("item0");
arrlist.add("item1");
arrlist.add("item2");
arrlist.add("item3");
foreach (int n in new int[3] )
移除值為0的第乙個元素
移除index為3的元素
for (int i = 0; i < arrlist.count; i++)
hashsethset = new hashset();
hset.add("item0");
hset.add("item1");
hset.add("item0");
hset.add("item0");
foreach (string item in hset)
//foreach=item0
//foreach=item1
//列表
//list.
listlist = new list();
list.add("item0");
list.add("item1");
list.add("item2");
for (int i = 0; i < list.count; i++)
list.removeat(0);
debug.write("刪除掉乙個元素\n");
for (int j = 0; j < list.count; j++)
debug.write("或者用foreach來遍歷\n");
foreach (string item in list)
debug.write("新增陣列\n");
list.addrange(new string );
list.foreach(showitem);
private static void showitem(string item)
//佇列
//先進先出
queuequeue = new queue();
queue.enqueue("item0");
queue.enqueue("item1");
queue.enqueue("item2");
queue.enqueue("item3");
foreach (string item in queue)
debug.write("__________________用while方式_________________\n");
while (queue.count > 0)
//棧
//先進後出
stackstack = new stack();
stack.push("item0");
stack.push("item1");
stack.push("item2");
stack.push("item3");
foreach (string item in stack)
debug.write("__________________用while方式_________________\n");
while (stack.count > 0)
//鍊錶
linkedlistllist = new linkedlist();
linkedlistnodenode = new linkedlistnode("root");
llist.addfirst(node);
node = llist.addafter(node, "item0");
node = llist.addafter(node, "item1");
node = llist.addafter(node, "item2");
node = llist.addafter(node, "item3");
foreach (string item in llist)
node = llist.first;
debug.writeline("第乙個元素:" + node.value);
node = llist.last;
debug.writeline("最後乙個元素:" + node.value);
mylistlist = new mylist();
for (int i = 0; i < 10; i++)
foreach (string item in list)
//item9
//item8
//item7
//item6
//item5
//item4
//item3
//item2
//item1
//item0
mylistlist = new mylist();
for (int i = 0; i < 10; i++)
foreach (int item in list)
//9//8
//7//6
//5//4
//3//2
//1//0
sortedlistslist = new sortedlist();
slist.add(5, "item0");
slist.add(25, "item1");
slist.add(24, "item2");
slist.add(475, "item3");
foreach (keyvaluepairitem in slist)
dictionarydict = new dictionary();
dict.add(141, "item0");
dict.add(46, "item1");
dict.add(541, "item2");
dict.add(21, "item3");
foreach (keyvaluepairitem in dict)
dict.containskey("***");//判斷有沒有包含這個key
dict.containsvalue("***");
排序,從小到大:
dictionarydictsorted = dict.orderby(o => o.key).todictionary(o => o.key, p => p.value);
foreach (keyvaluepairkv in dictsorted)
從大到小:
dictionarydic1desc = test.orderbydescending(o => o.key).todictionary(o => o.key, p => p.value);
用for迴圈遍歷:
listindexlist = new list(dictsorted.keys);
// 按照新的dict來獲取值
for (int i = 0; i < dictsorted.count; i++)
sorteddictionarydict = new sorteddictionary();
dict.add(23, "item0");
dict.add(54, "item1");
dict.add(132, "item2");
dict.add(12, "item3");
foreach (keyvaluepairitem in dict)
//key=12,value=item3
//key=23,value=item0
//key=54,value=item1
//key=132,value=item2
datatable datatable = mysqlitehelper.executedatatable(sqltext);
for (int i = 0; i < datatable.rows.count; i++)
}
C 中的物件指標總結
指向物件的指標 在建立物件的時候,變異系統會給每乙個物件分配一定的儲存空間,以存放其成員。物件空間的起始位址就是物件的指標。可以定義乙個指標變數,用來存放物件的指標。乙個簡單的示例1.1 複製 如下 include using namespace std class student student ...
C 中物件的常引用總結
直接傳遞物件名 用物件名做函式引數時,在函式呼叫時將建立乙個新的物件,它是形參物件的拷貝。下面給出乙個直接傳遞物件名的例子程式1.1 複製 如下 include using namespace std class time time time int y,int m,int d void time ...
C 中的集合
集合 集合包括 arraylist,hashtable 雜湊表 list,dictionary 字典 1 arraylist 定義 arraylist mylist new arraylist arraylist 可變長度陣列,使用類似於陣列 新增資料 arraylist array new arr...