andrewducker: (Default)
[personal profile] andrewducker
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.)

Date: 2009-10-22 11:49 am (UTC)
From: [identity profile] channelpenguin.livejournal.com
ah, it's the little things sometimes.

I wrote my own wrapper function using generics for that cos it drove me nuts. Not all that much shorter syntax but some improvement.

Date: 2009-10-22 09:54 pm (UTC)
From: [identity profile] the-locster.livejournal.com
Not BCL but have been using the Parallel Extensions a fair bit lately, e.g.

Parallel.ForEach(itemList, delegate(ItemType item)
{
Process(item);
});

The CTP is a bit rough around the edges, e.g. if the list has fewer than 8 items then it only uses one thread. But yeh, it's pretty useful at times for heavyweight algorithms.

Still no equivalent of Mono.Simd (maps onto CPU vector instructions). But the sppedups prob not that great anyway, especiallly when using hyperthreading to better utilise CPU resources. And I figure Parallel Extensions are gearing up for Intel Larabee and similar which MMX/SSE look a bit old hat.

March 2026

S M T W T F S
1 2 3 4 56 7
8 9 10 11 12 13 14
15 161718192021
22232425262728
293031    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Mar. 17th, 2026 03:44 am
Powered by Dreamwidth Studios