Oct. 22nd, 2009

andrewducker: (Default)
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.)
andrewducker: (Default)
Given a particular case I need to make four contols invisible.

I can just say:
control1.visible = false;
control2.visible = false;
label1.visible = false;
label2.visible = false;
but it seems awfully longwinded.

You can shorten it a bit to:
control1.Visible = control2.Visible = label1.Visible = label2.Visible = false;
but that's pretty awkward to read, and has redundancy too.

I think that C# lambda functionality would allow me to end up with code something like:
{label1,label2, control1,control2}.Set(Control c => c.visible=false;)
but that also seems pretty clunky (I can't check that syntax at work, we're using VS 2005, which doesn't support lambdas).

Is there a language that would let you do this?:
{label1,label2, control1,control2}.Visible = false;

August 2025

S M T W T F S
      1 2
3 4 5 6 7 8 9
10 11 12 13141516
17181920212223
24252627282930
31      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 13th, 2025 10:04 am
Powered by Dreamwidth Studios