Andrew Ducker (andrewducker) wrote,
Andrew Ducker
andrewducker

Things that cheer Andy up #76112

I just found this piece on the latest version of the BCL (base class libraries) that will arrive in .Net 4.

And I'm delighted to see that they're simplifying a couple of things that have been a bit of a pain so far.  My favourite of which is converting strings to enums, which used to require:
try 
{
    string value = Console.ReadLine();
    FileOptions fo = (FileOptions)Enum.Parse(typeof(FileOptions), value);
    // Success
}
catch 
{
    // Error
}
but is now
string value = Console.ReadLine();
FileOptions fo;
if (Enum.TryParse(value, out fo)) {
    // Success
}
(and that TryParse is clearly using inferred typing - in the same pattern that I tend to use in my code.)
Subscribe

  • Interesting Links for 05-05-2021

    The world's biggest jeweller, Pandora, says it will no longer sell mined diamonds and will switch to exclusively laboratory-made diamonds (tags:…

  • instagram cross-post

    Sophia stroking Jim in bed at night. The other day I left her alone for a few minutes and came back to find him on her bed. She said "He's been…

  • Interesting Links for 04-05-2021

    What if Uber - but superheroes? (tags: superheroes business roleplaying ) Biden at 100 Days: Boring as a Secret Weapon (tags: politics usa )…

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

  • 2 comments