CodingC# 3.0

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  THERE IS NO GOD BUT (RENDLE)  
 To:  ALL
31863.1 
Glee. I just got the January CTP of Visual Studio 9.0, with C# 3.0. It's got LINQ: Language Integrated Natural Query.

So, if I want to find all the items on a ToolStrip which are Buttons, are enabled and have their display style set to Image, I used to do this:

C# code:
List<ToolStripButton> buttons = new List<ToolStripButton>;
 
foreach (ToolStripItem item in toolStrip1.Items)
{
    ToolStripButton button = item as ToolStripButton;
    if (button != null)
    {
        if (button.Enabled && button.DisplayStyle == ToolStripItemDisplayStyle.Image)
        {
            buttons.Add(button);
        }
    }
}


But now I can do this, instead:

C# code:
var buttons = from button in this.toolStrip1.Items.Cast<ToolStripItem>()
              where button is ToolStripButton
              && button.Enabled
              && ((ToolStripButton)button).DisplayStyle == ToolStripItemDisplayStyle.Image
              select button;


(That Cast<ToolStripItem> bit won't be necessary in the final release, once they get the type-inference algorithm working properly.)

You can use similar code to "query" XML and relational databases, too. Where's your Delphi now, bitches?

0/0
 Reply   Quote More 

 From:  Ben (BENLUMLEY)  
 To:  THERE IS NO GOD BUT (RENDLE)     
31863.2 In reply to 31863.1 
i knew this thread would be from you
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  THERE IS NO GOD BUT (RENDLE)     
31863.3 In reply to 31863.1 
Interesting.

But...
code:
((ToolStripButton)button).DisplayStyle == ToolStripItemDisplayStyle.Image

That still very much bugs me.


Let me know when they allow something like:
code:
button.checkDisplayStyle('image')
Which would do exactly the same thing, but is half as much text and infinitely more readable and sensible.
0/0
 Reply   Quote More 

 From:  THERE IS NO GOD BUT (RENDLE)  
 To:  Peter (BOUGHTONP)     
31863.4 In reply to 31863.3 
But not compile-time type-checked, and therefore entirely worthless and shit.

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  THERE IS NO GOD BUT (RENDLE)     
31863.5 In reply to 31863.4 
People who can't write code themselves and need compilers holding their hand are worthless and shit.
0/0
 Reply   Quote More 

 From:  THERE IS NO GOD BUT (RENDLE)  
 To:  Peter (BOUGHTONP)     
31863.6 In reply to 31863.5 
Shut up, Peter.

0/0
 Reply   Quote More 

 From:  Ben (BENLUMLEY)  
 To:  ALL
31863.7 
GEEEKS
0/0
 Reply   Quote More 

 From:  Serg (NUKKLEAR)  
 To:  ALL
31863.8 
Ihatewriting*any*code
0/0
 Reply   Quote More 

 From:  Rowan  
 To:  Peter (BOUGHTONP)     
31863.9 In reply to 31863.5 

People like you should be left on ice floes in the night.

 

The wheel -> sliced bread -> type safety.

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Rowan     
31863.10 In reply to 31863.9 
quote:
The wheel -> sliced bread -> type safety.

Aye, and if it'd been "type safety -> the wheel -> sliced bread"... well, we'd still be trying to figure out (wheel)StoneSlab.HoleType.Add(AxelTypes.Branches.StrongBranchAxel) and wouldn't even have got round to sliced bread!

90% of the time, type checking is just useless bureaucracy.
0/0
 Reply   Quote More 

 From:  Rowan  
 To:  Peter (BOUGHTONP)     
31863.11 In reply to 31863.10 

P1) Typing makes people jump through hoops.
P2) Some people don't like jumping through hoops, because it means they have to think about what they're doing, which they don't normally.
P3) People who don't normally think about what they're doing are more likely to write unsafe code.
C1) People who don't like types are more likely to write unsafe code.

 

Of course, I'm clearly not going to come close to changing your mind, and I don't really care that much. I just fancied poking you with a stick, a bit.

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Rowan     
31863.12 In reply to 31863.11 
But its a soft foam stick swaddled in cotton wool you're poking me with.

You wont change my mind because I know its just as safe to wear knee and elbow pads and you don't get slowed down with over-cautious fluff.

*shuts up*
0/0
 Reply   Quote More 

 From:  Rich  
 To:  THERE IS NO GOD BUT (RENDLE)     
31863.13 In reply to 31863.1 
Even so, the generic + foreach reads much nicer to me :)

Rich - e - w - m
0/0
 Reply   Quote More 

Reply to All    
 

1–13

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats