国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

老外編的程序(四)--HashTable的使用示例

2024-07-21 02:20:12
字體:
來源:轉載
供稿:網(wǎng)友
using system;
using system.collections;
using system.text;

public class sampleshashtable  {
    public static void main()  {
        // create and initialize a new hashtable.
        hashtable table = new hashtable();
        //student name, grade
        table.add("jay", 100);
        table.add("brian", 87);
        table.add("rajesh", 92);
        table.add("bill", 76);
        table.add("brad", 84);
        table.add("kit", 91);
        table.add("vinaya", 80);
        table.add("lakshan", 87);

        // display the properties and values of the hashtable.    
        console.writeline("count: {0}", table.count );
        printtable( table );

        console.writeline();
        int g = (int) table["jay"];
        console.writeline ("jay's grade is: {0}", g);

        console.writeline();
        printitems ("all names", table.keys);
            
        console.writeline();
        printitems ("all grades", table.values);

    }
    public static void printtable( hashtable mylist )  {
        console.writeline ("{0,-8} {1,-8}", "name","grade");
        console.writeline ("{0,-8} {1,-8}", "----","-----");
        foreach (dictionaryentry e in mylist) {
            console.writeline ("{0,-8} {1,-8}", e.key, e.value);
        }
    }
    public static void printitems(string title, ienumerable    mylist )  {
        console.write ("{0}: ", title);
        stringbuilder sb = new stringbuilder();
        foreach (object o in mylist) {
            sb.appendformat( "{0}, ", o);
        }
        sb.remove (sb.length-2,2);
        console.writeline(sb);
    }
}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 梁河县| 泽普县| 若羌县| 民乐县| 璧山县| 陕西省| 大洼县| 达孜县| 婺源县| 浦北县| 沙洋县| 凤山市| 海安县| 茂名市| 东莞市| 沧源| 疏勒县| 宜州市| 罗田县| 苍南县| 河东区| 旬阳县| 大厂| 南皮县| 浦北县| 汝城县| 龙川县| 三原县| 镇赉县| 建宁县| 潮州市| 天长市| 怀宁县| 玛沁县| 楚雄市| 封开县| 紫金县| 镇坪县| 玉林市| 水城县| 弥勒县|