• bvs23bkv33 (unregistered)

    first or default comment

  • LCrawford (unregistered)

    FristOrDefault() is tricky - it is not clear at first glance that it can return null since it's supposed to return the default(), right? But the default for object types is null.

  • (nodebb) in reply to LCrawford

    FristOrDefault() is tricky - it is not clear at first glance that it can return null since it's supposed to return the default(), right? But the default for object types is null.

    FristOrDefault() { default="Secnod"; if ( List<Post>.length == null ) return Frist; return default; }

  • Anon (unregistered)

    How bad must the original system have been that this code beat it?

  • (nodebb)

    Keep concurrency in mind, there's a class which does this in a thread safe fashion.

  • BLTCollector (unregistered)

    Has cornify.com been abandoned? Its SSL cert has been expired for a week. WHERE ARE MY UNICORNS AND RAINBOWS?!

  • (nodebb)

    Throw EOutOfNullsException();

  • Barf4Eva (unregistered)

    Jeeeez... Anything to work around simple and efficient... :P

  • MaxiTB (unregistered)

    A C# dictionary cannot contain keys with the value of null. Additionally FirstAndDefault() exactly does what it says, it reurns the default value which can be a ValueType (something Java doesnt have, so I understand the confusion).

    So is the WTF the explaination whats wrong with the code or the imaginary problems?

  • Pedant (unregistered)

    Aside from the issues highlighted in the article, this is a good example of a common mistake where people use FirstOrDefault in a scenario where there should only be zero or one result ... so they should have been using SingleOrDefault.

  • Anon The Mouse (unregistered)

    Re: Misuse of Map/Dictionary...

    Programmers here created Map<Integer, Object> thingers so they could use 1-based indexed "arrays."

  • Klaus (unregistered) in reply to Anon The Mouse

    Occasionally, 1-based arrays can make implementations easier. Heck, Fortran has arbitrary starting indices for that reason, e.g. when representing a symmetric function numerically as a -42,-41,...,41,42 array.

    But putting it into a Map object sounds pretty JavaScript :)

Leave a comment on “The Key to Using Dictionaries”

Log In or post as a guest

Replying to comment #501700:

« Return to Article