国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 彩票| 金乡县| 阳泉市| 当涂县| 鹤庆县| 内江市| SHOW| 新民市| 西丰县| 延安市| 岳西县| 惠州市| 广州市| 丹江口市| 屏边| 西盟| 会泽县| 东平县| 峨山| 阳山县| 喀喇沁旗| 延安市| 正蓝旗| 远安县| 文山县| 威宁| 资源县| 定边县| 宁国市| 屏边| 麦盖提县| 衡水市| 玉田县| 申扎县| 泸溪县| 三河市| 金寨县| 交口县| 兴山县| 岐山县| 隆尧县|