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:
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.)