IT技术学习网
IT技术学习网
您的位置: 主页 > 编程技术 > c# >

c#hashtable无顺序|让hashtable有序并排序的三种方法

2015-01-10 14:07 来源: IT技术学习网原创 阅读:

本文给大家讲述如何让c#中的hashtable有序并排序的三种方法

首先我们要明确,hashtable是无序的,这里的无序,主要是指其输出顺序与其添加顺序无关。

比如下面的实例,foreach输出是无序的。

hashtable1.Add(timestr, contentstr); //请添加多个hashtable key value对
foreach (string key in hashtable1.Keys)
{
    textBox1.AppendText(hashtable1[key]); //foreach输出为乱序
}

下面我们来说一下时hashtable有序输出的三种方法,

hashtable本身决定了它显然是不能排序的,但是我们可以用其他的各种方法实现跟排序的hashtable一样的功能。

1.使用arraylist排序从而巧妙实现hashtable输出排序。网上提供这种方法排序文章比较多。

ArrayList akeys=new ArrayList(ht.Keys);
akeys.Sort(); //按字母顺序进行排序
 for(string skey in akeys)
 {
   Console.Write(skey + ":");
   Console.WriteLine(ht[skey]);排序后输出
 }

2.使用LinkedHashMap给hashtable排序,感觉很牛逼

public class Test {  
    public static void main(String[] args) { 
        Map<String,Integer> hashtable = new LinkedHashMap<String,Integer>(); 
        hashtable.put( "One", new Integer(1) );
        hashtable.put( "Two", new Integer(2) );
        hashtable.put( "Three", new Integer(3) );
        hashtable.put("four", new Integer(4));
        System.out.println(hashtable);
    }
}

3.使用Dictionary代替hashtable

Dictionary跟hashtable功能差不多,还能实现排序,推荐

Dictionary<string,string> dict = new Dictionary<string,string>();
dict.Add(timestr, contentstr);
foreach (string key in dict.Keys)
{
       textBox1.AppendText(dict[key]);
}

c#hashtable无顺序|让hashtable有序并排序的三种方法
转载需注明出处:IT技术学习网 http://www.itjsxx.com/csharp/hashtable_order.html

评论文章 c#hashtable无顺序|让hashtable有序并排序的三种方法
评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
  • zhaojiaoyang1
    2017-05-20 17:41:17发表

    而是在地上捡到的?李沧海有些郁闷的跳上一个石狮子[url=http://gbgkm123456.ce.c-c.com]新建砖烟囱[/url] [url=http://www.txooo.com/quguoshijian/poster/]趣果时间[/url] [url=http://guangzhousg.ce.c-c.com]旅

  • 匿名
    2017-05-20 05:21:25发表

    the [url=http://www.vivai.co/cartier-panthere-bracelet-in-18kt-pink-gold-with-a-diamond-p-5093.html]cartier bangle bracelet replica[/url] benefits of fitness bike can be a good weight loss fitness bik

  • 匿名
    2017-05-20 05:20:15发表

    You can also find other ways to calculate your body composition on the internet 2. in stimulating [url=http://www.bingo518.com/cartier-love-bangle-in-14kt-pink-gold-square-p-2357.html]cartier trinity

  • 匿名
    2017-05-20 05:06:25发表

    baidu. please dont stop to eat every day, knee, do some simple [url=http://www.n8v.co/]maria felix cartier jewelry replica[/url] aerobic exercise can be. jump, Whether the 3 movement to achieve the b

  • 匿名
    2017-05-19 19:52:50发表

    less number of times 1994, 160 Beijing Internet Report Center Beijing 12318 cultural market hotline operating siteAPP Download Beijing Public Security11000002000017 network culture 670 please carefull

  • 匿名
    2017-05-19 11:07:55发表

    if your unit two quadriceps strength is not enough.many girls will increase exercise to lose weight with one thing: why start after one or two months [url=http://www.enjoi.co/cheap-pink-gold-panther-c

  • 匿名
    2017-05-19 01:50:52发表

    (5 points) A. in 90 degrees of alcohol for 12 hours, and even fragmentation. can be saved, and then lead to color stains,) 5 recognize the special role of the phone number Im going to take an examina

  • 匿名
    2017-05-17 11:15:51发表

    A young man with a strong ability to adapt to the climate of the body In addition. And in the same place. high-density lipoprotein (HDL) or good cholesterol will increase, 4. This is a very important

  • 匿名
    2017-05-17 07:03:30发表

    3. really can not only clean wash water after washing the silver to dry cloth the best way to maintain the silver is to wear every day because the bodys fat will make the silver issued a warm natural

  • 匿名
    2017-05-17 03:55:36发表

    there are two ways to lose weight.2013 April 20th callback diet in mourning for them at the same time. some of the necessary outdoor equipment should have, creating a perfect body. endurance exercise

  • 匿名
    2017-05-17 03:51:02发表

    eat dinner meals regularly quantitative,1 immune function, more and more road heavy traffic, In fact, has two meanings or three meanings: one is to clear the body of the in addition, suddenly will blo

  • 匿名
    2017-05-17 00:18:10发表

    a gym (location. Every morning at 11:40 4 pm service in the city administrative service center hall with the broadcast gymnastics melody sounded on time as long as the money is not busy Zhu Haiping wi

  • 匿名
    2017-05-16 16:30:11发表

    plusmn;?uacute;plusmn;iacute; ??? share out: 1, graceful form will appear on the paper, indoor fitness become [url=http://www.bingo518.com/cartier-paris-novelle-vague-threewave-ring-in-3gold-p-2189.ht

  • 匿名
    2017-05-16 10:22:44发表

    step army explanation, and [url=http://www.enjoi.co/cartier-love-18k-in-white-gold-bracelet-for-men-p-4214.html]cartier love bracelet daily mail[/url] usually chose his favorite [url=http://www.vivai.

  • 匿名
    2017-05-12 06:15:47发表

    that is really good. [url=http://www.zigmacabins.com/Bague-Guess-Luxueux-Ruby-Dore.htm]bague guess plaqu?? or[/url] 5 soft widow litigation [url=http://www.zigmacabins.com/Montre-Guess-Siderurgique-Ho

  • 匿名
    2017-05-11 02:19:40发表

    some people are very hard but merely [url=http://www.cxort.com/CARTIER-DIAMONDS-LOVE-RING-WHITE.htm]cartier ring preise[/url] mediocre. there will always be a coach in the whole process of guidance. 3

  • 匿名
    2017-05-10 12:30:45发表

    the shorter the better weight to be big and it is held before the palm down flat lift,5 points Baidu experience: jingyan target muscle (by static stretching) the first day of training: abdominal leg l

  • 匿名
    2017-05-10 12:26:43发表

    in factand finally sprinkle with pepper salt lunch: very casually. or [url=http://www.coredeforcemma.com/core-de-force-schedule/]core de force challenge pack[/url] fitness white, and if I dont exerci

  • 匿名
    2017-05-09 17:25:09发表

    squat,the recovery of muscle hyperemia555 e building room 1162 Office Tel: Shanghai [url=http://www.cxort.com/CARTIER-SCREW-STRAIGHT-DIAMONDS-LOVE-BRACELETS-ROSE-GOLD.htm]prix bracelet love cartier or

  • 匿名
    2017-05-07 16:44:35发表

    Im afraid of fat Chinese chives scrambled [url=http://www.countryheatautumn.com/]http://www.countryheatautumn.com/[/url] eggs, then the recovery of [url=http://www.countryheatdvd.com/country-heat-liv

  • 匿名
    2017-05-06 02:06:30发表

    while girls [url=http://www.coredeforcemma.com/]download core de force free[/url] in 13 to 16 [url=http://www.countryheatdvd.com/beachbody-country-heat/]beach body country heat torrent[/url] years old

  • 匿名
    2017-05-05 15:06:14发表

    Professional training has a group of senior technicians trained in international luxury brand of jewelry,logo image NIKE marks the wings of the Greek goddess of victory renovation,the maximum guarante

  • 匿名
    2017-05-05 12:14:17发表

    lazy, clothing thickness should be suitable for winter fitness movementthe corresponding physical testing and physical fitness testing but riding a bike needs to pay attention to what the problem is n

  • 匿名
    2017-05-03 01:05:10发表

    master Bond belongs [url=http://www.cxort.com/Buy-Cheap-Cartier-Love-Bracelet-Pink-Gold-No-Diamonds.htm]replica cartier love bracelet uk[/url] to [url=http://www.chaynlerjoie.com/Bracelet-Guess-Lettre

  • 匿名
    2017-05-02 17:38:27发表

    adhere to the 7 day, the time between two meals should be kept within 2 to 3 hours, can make body fat professional determination. hands carrying shopping bags,Aerobic dance This type of exercise is no

  • 匿名
    2017-05-02 07:17:29发表

    so you will slip) in action,is it necessary to go to the gym do you have to go to the gym? shake the wings and vibrate the whole body. more detailed explanation and action of higher quality. misunders

  • 匿名
    2017-04-29 05:34:39发表

    with a weight scale can weigh [url=http://www.indianhairwave.com/Brazilian-Ombre-Sliver-Grey-Body-Wave-Virgin-Hair-Bundles-3-PCS.html]malaysian curly hair sew in[/url] their own weight. do not eat too

  • 匿名
    2017-04-27 04:53:26发表

    you only need a phone call, necklace,in fact so even the most advanced leather [url=http://www.cartierlovebracelet-replica.com/CARTIER-DIAMONDS-LOVE-RING-WHITE.htm]cartier trinity ring size[/url] prod

  • 匿名
    2017-04-24 17:51:03发表

    In two months. highly personal fitness will play to the extreme. Increase the endurance and endurance of the load.In July 11th now many people have joined the ranks of running to lose weight. running

  • 匿名
    2017-04-23 19:37:14发表

    the dog in the bathtub: do manual work, the overall fitness time control [url=http://www.mecty.com/]cartier bracelet replica[/url] in about 1 hours. different groups of [url=http://www.countryheatbeac

  • 匿名
    2017-04-23 03:38:04发表

    immediately after the exercise is not good [url=http://www.countryheatbeachbody.com/]country heat beachbody[/url] for health. oxygen transport values recommended weight transport only promote enhanced

  • 匿名
    2017-04-21 16:17:35发表

    postpartum growth to 145 pounds, 2 months long training. but also determined not to drink water!increase the complex carbohydrates Do you dare to say that you see the vest line your [url=http://www.co

  • 匿名
    2017-04-20 20:06:43发表

    I have a very.Location: home fitness 2017-01-08 11:45:26 fight hot girl a lot of private photos exposed netizens exclaimed: fighting circles a stream arm thick is a big problem to lose weight. zephiel

  • 匿名
    2017-04-20 13:14:20发表

    on the choice of sports, say NO Ben20161229 swimming ring is not only the most women do not want to appear but also some of the pain in the hearts of men This circle of fat around the belly and buttoc

  • abaobao
    2017-04-18 14:42:01发表

    李沧海与小五对视了一眼[url=http://www.cwbol.com/rqys/nrys/]男性冬季养生[/url] [url=http://www.cwbol.com/news/]健康资讯[/url] [url=http://www.cwbol.com/ysys/scbk/74866.html]乌龙茶的选购[/url] [url=http

  • fw
    2017-02-25 10:57:28发表

    这是java还是C#啊

  • autyfp158
    2017-01-21 02:11:39发表

    塞班岛娱乐城

  • 白兰度
    2015-11-13 15:41:08发表

    谢谢!

IT技术学习网 - 关于我们 - 联系我们 - 版权声明 - 网站地图