C# : Difference between Hashtable and Dictionary


 

When we want a collection  data structure to hold data as key/value pairs, we have two obvious choices.

1. Dictionary

2. Hashtable

So basically what is the difference between both this and when to use which. Lets check it out. Point by Point.

1) Generics

Dictionary is a generic type, Hashtable is not. Now what that means. This is the most important aspect one should consider when taking decision. Dictionary is a generic type means

- You get type safety with Dictionary, because you can’t insert any random object into it, and you don’t have to cast the values you take out.

- And also generic collections are a lot faster as there’s no boxing/unboxing

- Hashtable uses Object to hold things internally (Only non-generic way to do it). So you have to take care of type safety and cast it to appropriate data type when you take it out, but it also means that you can add keys and values of any type ( It is good or bad, well it depends :) )

- Again Hashtable also have to box/unbox, which may have memory consumption as well as performance penalties.

2) Thread Safety :

In .Net Hashtable is thread safe for use by multiple reader threads and a single writing thread, while in Dictionary public static members are thread safe, but any instance members are not guaranteed to be thread safe.

One more thing that can make difference is,  we can not use dictionary (generics) with web services. The reason is no web service standard supports generics standard.

Technorati Tags: ,,,,,,,,

Windows Live Tags: C#,Hashtable,Dictionary,collection,Generics,instance,services,supports,collections

WordPress Tags: C#,Hashtable,Dictionary,collection,Generics,instance,services,supports,collections

Follow me on Twitter |


  • http://www.abhisam.com/SafetyInstrumentedSystems.htm functional safety

    This is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your posts, I guess I am not the only one having all the enjoyment here! Keep up the good work.

  • http://www.onlineflashgames.org/ games online free

    Hello, your blog’s theme is fantastic and . Your articles are amazing. Please keep them coming. Greets!!

  • http://www.arcadeshell.com/ online games

    Hello admin, eye-popping post! Please keep them coming!!

  • http://none/ atwood

    Hentai is upright like any other TV shows having all forms of the genre. Animation also delves into action, comedy, romance and even sexuality. The latter being a controversial type is uniquely classified as "hentai." Indeed, pornography has a new semblance in animations. Magazines, computer games, anime TV series and movies now have their respective sexually distinct twists. This paradigm of zest caters to the needs of the older viewers as more adults evolve into satisfied fantasizing with sensual themes, anime-style. The reason behind the use of sex in anime is that it is the lone medium that can showcase some sexy fantasies that are too unachievable forreal people to take out like the use of peculiar fetishes or the application of extreme violence in pure animation format. Certain concepts that are too good to be true and are often widely considered taboo in the society can now become the dominant focus of anime, without passing through all major controversies that may be brought upon by real life like films. Accessing hentai sites are commonly done with payment, although there are still lots of video on demand and streaming domains that make them completely free of charge to users. If the latter happens then one can directly indulge in different sexual fantasies may it be lesbian, gay or straight. Moreover, recreation can also be present in hentai as you tend these blue animations that are adapting the same storyline and perceptible characters from the original hit anime TV shows. The easiest way to watch Hentai Online is by visiting a free site like <a href="http://www.hentaicrazed.com/koihime-episode-01-english-dubbed.html">Koihime Episode 01 English Dubbed</a> and signup with their sponsors as soon as you decide you want to watch something more specific. For a small one time investment you will have access to live sports, full episodes, movies, rumours, weather and much more.

  • http://www.googlelove.info/ search engine optimization consultant

    There are certainly a lot more details to take into consideration, but thanks for sharing this information.

  • http://cardrivingphobia.com/ scared of driving

    This was novel. I wished I could analyze every post, but i have to go back to work now… But I’ll be back.

  • http://sufbay.com/indonesia-java-international-destination.html indonesia java international destination

    hello, this is my first time i visit here. I found so many interesting in your blog especially on how to determine the topic. keep up the greatwork.

  • http://www.goarticles.com/cgi-bin/showa.cgi?C=1931494 buy acai berry

    You should consider giving a similar list of websites for people who like this. I came across your blog last week when I was googling, but I’m not really into the blog thing. I don’t think it’s because I don’t enjoy blogs, but more than likely due to the fact that I’m slightly behind to them.

  • http://christianbooks.corank.com/tech/story/the-Important-of-Church-Candles Bianca Dick

    Rather good post, definitely useful information. Never ever believed I would obtain the facts I would like right here. I’ve been scouring everywhere in the net for a while now and had been starting to get frustrated. Thankfully, I came onto your website and received exactly what I was browsing for.

  • http://www.mooladays.com/ how to make more money

    I am impressed with all this useful information. Was WAY more than I expected. I just cannot keep up with your posts. So much information to read about.

  • http://sufbay.com/indonesia-java-international-destination.html indonesia java international destination

    I haven’t any word to appreciate this post. nice post.

  • http://barcodeinventorysystem.org/ barcode inventory software

    Excellent post I must say.. Simple but yet interesting and engaging.. Keep up the awesome work!

  • http://blogroute.com/ blog

    Excellent post I must say.. Simple but yet interesting and engaging.. Keep up the awesome work!

  • http://mlbloggingplrsystem.info/ how to start a blog

    I was just browsing for relevant blog posts for my project research and I happened to stumble upon yours. Thanks for the useful information! :-)

  • http://www.manageweightloss.net/ fitness

    Took me awhile to read all the comments, but I really enjoyed the article. It proved to be very useful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also engaged! I’m sure you had joy writing this article.

  • http://www.ebooktimes.com/ download free ebooks

    I wanted to thank you for this excellent read!! I definitely loved every little bit of it. I have you bookmarked your site to check out the new stuff you post.

  • http://eoy2000.com/ Tampa Bay Website Design

    I was just browsing for relevant blog posts for my project research and I happened to stumble upon yours. Thanks for the excellent information! :-)

  • http://www.squidoo.com/Start-A-Preschool Helen Fulk

    Great Point. Great story. haha I dig this blog! It rarely ceases to amaze me why people do the things they do though. :)

  • http://www.discburner.org/ Dvd Burner

    Good information. Search engine rankings has come to a level where your anchor text and the amount of links you get matter the most. Even before the blogs coming into scene or Google was in power, webmasters would submit their websites to as many directories as possible to get any traffic they can.

  • http://www.starlitt.com/ newsletter,

    This is my first time i visit here. I found so many interesting stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the excellent work.

  • http://www.photostudio-koepenick.de/ Alexander

    Hey! I have been following your blog for 6 days now and i should say i am beginning to like your posts.I guess im subscribing now for not missing anything new.

  • http://www.thedsguide.com/ nintendo ds games review

    Aw, this was a really great post. In theory I’d like to write like this too – taking time and real effort to make a good article… but what can I say… I procrastinate alot and never seem to get anything done.

  • http://www.k1-kickboxing.com/ k1 kickboxing

    Hi. I just noticed that your site looks like it has a few code problems at the very bottom of your website’s page. I’m not sure if everybody is getting this same error when browsing your website? I am employing a totally different browser than most people, referred to as Opera, so that is what might be causing it? I just wanted to make sure you know. Thanks for posting some great postings and I’ll try to return back with a completely different browser to check things out! Also, I put a link to your blog at my site,hope you dont mind?

  • http://twitter.com/mikesmith0762 Antwan Skibski

    Although I would have loved it more if you added in a relevant video or at the least images to back up the description, I still thought that your post quite useful. It’s normally challenging to make a complex subject matter look so easy. I value your site and will register for your feed so I won’t miss out on anything. Awesome posts

  • http://navigationsystemsforcars.spaces.live.com/ Andrew Mann

    Looks like it hit the spot. good post.

  • http://www.buildersmelbourne.net/ Javier Guss

    Thanks for this. We all like a bargain and your advice helps

  • http://www.discounttrainsonline.com/Atlas-Caboose-Extended-Vision-RAP--Conrail-22130/item150-30243.html Ebonie Slaight

    I don’t agree with everything in this piece of writing, but you do make some very good points. I’m very interested in this topic and I myself do alot of research as well. Either way it was a well thoughtout and nice read so I figured I would leave you a comment. Feel free to check out my website sometime and let me know what you think.

  • http://realromanceinfo.com/ dating

    This is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your posts, I guess I am not the only one having all the leisure here! Keep up the excellent work.

  • http://www.buyanannuity.net/ buy an annuity

    This is a really good read for me. Must agree that you are one of the best bloggers I ever saw. Thanks for posting this informative article.

  • http://www.dadhints.com/ positive parenting

    Splendidly written posting, if only all bloggers put up this level of high-level quality information the internet would be a much better place. Please keep it up! Thanks.

  • http://www.numerologist.com/?hop=bgl01 numerologist.com

    Nice job. I really like the layout of your site. Do you know Which theme are you using?

  • http://www.indonesianteakfurnituremanufacturers.com/ Teak Furniture Manufacturer

    hello, this is my first time i visit here. I found so many interesting in your blog especially on how to determine the topic. keep up the greatwork.

  • http://www.alabamaestatemobilerealexpertsguide.info/ darren

    I also enjoy reading the comments, but notice that alot of people should stay on topic to try and add value to the original blog post http://www.alamocarrentalcouponexpertsguide.info

  • http://waterfront-urban-development.org/ Scientist

    You’re blog is very interested. We hope there are additional articles about science in this site, which will add to our knowledge. thanks

  • http://www.georgiadaycaredirectory.com/ Atlanta daycares

    This is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your posts, I guess I am not the only one having all the leisure here! Keep up the excellent work.

  • http://www.buyviagrainternet.com/ viagra uk where to buy

    Because of the constant trend in rising costs and the financial meltdown, people are beginning to pay more attention to their finances and spending. Everywhere around us, we observe this trend in the changing world.

  • http://www.stdsymptomstesting.info/ std testing

    Do you think you have STD symptoms? See pictures here http://www.stdsymptomstesting.info and to find STD testing.

  • http://www.all-digital-bookstore.com/ scripts

    Thanks for taking the time to share this, I feel strongly about it and love reading more on this topic. If possible, as you gain knowledge, would you mind updating your blog with more information? It is extremely useful for me.

  • http://astore.amazon.com/flip.ultrahd.camcorders-20 Sharon Peters

    I wish more blogs were as informative as this one.

  • http://astore.amazon.com/universal.apple.ipod-20 Burton Haynes

    Very informative blog I enjoyed reading it and am trying to absorb all the information. Definetely going to subscribe to your blog, you are certainly an expert on this topic.

  • http://maleextrareview.org.uk/ male extra
  • http://www.bondgirlslondonescorts.com/ london escort agency

    I enjoy your blog, couse I can read it from my Nokia.

  • http://bit.ly/9t4GVJ Smith

    as i was reading this i zoned out on how delicious these Free WELCHES fruit chews are from http://bit.ly/9t4GVJ :) (enter ur zip code 2 see what snack samples u can get for free) nothing beats free! lol keep it up w. the blog!!

  • http://hubpages.com/hub/Opalescence-Teeth-Whitening-Gel Rembrandt Teeth Whitener

    That is an exceptionally splendid editorial you have posted!

  • http://insurancereviewer.org/keyman-insurance Keyman Insurance

    Ah, I’m happy I added your blog to my bookmarks, otherwise I’d have missed this post! Thanks for this.

  • http://www.freebie-haven.com/ Sandy Hargroder

    Thanks for writing about this. There’s a lot of important tech info on the internet. You’ve got a lot of that info here on your site. I’m impressed – I try to keep a couple blogs fairly up-to-date, but it’s a struggle sometimes. You’ve done a great job with this one. How do you do it?

  • http://www.termite-1.com/ types of termites

    Took me awhile to read all the comments, but I really enjoyed the article. It proved to be very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also engaged! I’m sure you had fun writing this article.

  • http://www.leathercornersofas.org/ leather corner sofas
  • http://www.thegoldeconomy.com/ Jae Buie

    Thanks for the post, so to learn and such short time available in our lives!

  • http://www.leathercornersuite.org.uk/ leather corner suite

    Not that I have any intention to copy your website, but I really like the design. would you tell me what theme are you using? Or is it made especially for you?

  • http://hubpages.com/hub/Medical-Hair-Restoration-Cost Hair Transplant Laser

    This is an exceptionally amazing editorial you’ve put up here!

  • http://hubpages.com/hub/Automobile-Loan-Refinancing Refinancing Used Car Loan

    Thank you so much for this especially awe inspiring article!

  • http://whereizzi.com/copywriting Veda Hardter
  • http://copy.whereizzi.com/ Erasmo Fineran
  • http://inability-to-become-pregnant.blogspot.com/ Marlon Boots
  • http://top10seotools.com/ seo tools

    Howdy, i read your blog occasionally and i own a similar one and i was just wondering if you get a lot of spam comments? If so how do you prevent it, any plugin or anything you can advise? I get so much lately it’s driving me mad so any help is very much appreciated.

  • http://www.mymusicblog.tk/ Maria

    Lovely post. :)

  • http://www.mymusicblog.tk/ Fred

    It is exactly what I want to find. Thx.

  • http://www.mymusicblog.tk/ John

    Great job. I love it.

  • http://www.mymusicblog.tk/ Maria

    Great note. Fantastic site.

  • http://www.countypropertyrecords.org/ Property Records Search

    I read your posts from time to time and I must say that I love your template and of course your articles :-)

  • http://www.reversephonelookup.org/ reversewhitepages

    It’s nice site All the advice I discovered productive. We’ve saved it and will eventually come by back again soon after. With thanks.

  • http://www.buypanasoniccordlessphones.com/ Ivey Mcilwraith
  • http://laptopcomputercase.net/ computer case

    You do give a detail here. I have study a destiny about this on different articles written by other people, merely I must admit that you experience showed your point here!.

  • http://www.scat.ws/ Scatman

    Is the a limit on how long your comments can be? Timed out about 4 times when I was trying to post a 7 line long comment.

  • http://80sfancydresscostumes.co.uk/ Nicolas Senk

    You wouldnt believe how long ive been looking for something like this. Went through 6 pages of Google results couldnt find diddly squat. One search on Bing. There you are!…. Really have to start using it more often!

  • http://ez-biz.org/blog/ how to make money with a blog

    Hi, I can?t understand how to add your blog in my rss reader. Can you Help me, please? I really want to read your future posts.

  • http://hubpages.com/hub/How-To-Lose-Weight-Quick-1 Fastest Way To Lose Weight

    This is a fantastically impressive article you’ve published.

  • http://www.fatherofthegroomspeechinfo.com/ father of the groom speeches

    Hi. I just noticed that your site looks like it has a few code problems at the very top of your website’s page. I’m not sure if everybody is getting this same bugginess when browsing your website? I am employing a totally different browser than most people, referred to as Opera, so that is what might be causing it? I just wanted to make sure you know. Thanks for posting some great postings and I’ll try to return back with a completely different browser to check things out! Also, I put a link to your blog at my site,hope you dont mind?

  • http://www.detox-worldwide.tk/ acia berry detox

    Very interesting topic, im suscribing to blog.mahingupta.com, keep coming!

  • Dell Mercant

    Check this one….Dictionary and Hashtable

    Dell

  • http://ultimatenutritionz.com/ Natalia Loobo

    HGH X2
    Somatropinne Review – Crazy Bulk designed HGH-X2 Somatroppine to provide you
    with the best and safest formula for rapid muscle growth and fat burning,
    read review at

    http://ultimatenutritionz.com/hgh-boosters/crazy-bulk-hgh-x2-somatropinne-reviews/

  • http://www.dbalmax-reviews.com/ DBalMax


    D-Bal
    Max

    D-bal
    Max Reviews – Dianabol (methandrostenolone) often called Dbol, is an oral
    anabolic steroid that offers massive gains in very short periods.

  • Finley Gipson

    Crazy Bulk Australia 100% Safe and Legal Steroids

    Crazy Bulk is 100% safe and legal alternate steroids available in market right now. With 100% success rate and excellent muscle building effects from day one.

  • http://www.hiproleanxs-reviews.com/ jade moser
  • bipul kumar tiwari
  • bipul kumar tiwari