Things that cheer Andy up #76112
Oct. 22nd, 2009 12:29 pmI 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:
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 nowstring 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.)
no subject
Date: 2009-10-22 11:49 am (UTC)I wrote my own wrapper function using generics for that cos it drove me nuts. Not all that much shorter syntax but some improvement.
no subject
Date: 2009-10-22 09:54 pm (UTC)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.