I can’t count the number of times (unintentional pun) I’ve checked if an IEnumerable<T> sequence contains elements using Count().
static void Method(IEnumerable<Status> statuses)
{
if (statuses != null && statuses.Count() > 0)
// do something...
}
To get the count, the code has to traverse the entire sequence. On a long, lazy-executed sequences, this can take significant time. Since I only want to know if the sequence contains one or more elements, it’s computationally more efficient to use the Any() extension method.
static void Method(IEnumerable<Status> statuses)
{
if (statuses != null && statuses.Any())
// do something...
}
In this case, Any() will return after examining the first element in the sequence. It also reads a better (IMHO).
Day 2 is shaping up to be a much better conference day. Scott Guthrie really delivered the goods this morning with a look at Silverlight 4 and IE 9. It’s a great time to be a Silverlight developer. And speaking of Silverlight…
The Silverlight application that I and my colleagues developed was demoed in the keynote. That Siemens medical application that was shown. That was the handy work of none other than yours truly and of course my most excellent team members.
And then there was this other minor announcement about the conference attendees receiving a Microsoft custom made laptop. Yep, that’s right. And it’s not a wimpy little thing either. They did an incredible job keeping this a secret. There wasn’t even a rumor as far as I know.
I also have to take everything back about the lack luster swag this year. In fact, the laptop is one helleva of conference gift. My coworkers are all begging to have it, and who can blame them. It’s one sweet little, full-featured laptop. Part of me really wants to give it away but I suspect my more selfish instincts will prevail.
And in a rare instance of self restraint, I’ve elected not to pick it up until I’m on my way back to the hotel tonight. I figured it would be just too much of a distraction and I am here to attend the breakout sessions.
Speaking of breakout sessions, with the announcement of Silverlight 4, Microsoft also added a bunch of Silverlight 4 breakout sessions. Sly devils… The sessions were jammed pack as expected.
The cool thing is most of what has been announced in Silverlight 4 is going to put our medical application over the top. The doctors already love it but all these new features will enable us to literally rock their world. I’m looking forward to it.
As to the session content, it would take a long time to summarize all the stuff that came at us today. I’ll have to save that for another post. There was however a demonstration of an Azure cargo container server farm. Demonstration is perhaps the wrong word. It was the actual container complete with servers and liquid cooling. Inside, there’s a purple glow to everything. They also let us stand inside while they ran it full out. It can get quite chilly inside. Here’s some pictures.
Ouch, I just encountered my first hard Windows 7 bug. My SD card reader is not working. Guess I’ll have to wait until I get back home to download pictures with a USB cable. Bummer.
Guess it’s time to go pick up that laptop…
I was going to give a summary of the keynote proceedings but Dan Rigsby has already posted a great summary here.
It’s clear that Microsoft has really scaled back this year’s PDC. There is not much hype (at least for a PDC), the freebies, food and swag are “minimal” and the whole thing feels like a giant corporate yawn. Part of the fun of going to these events is to pickup on the “buzz” of what others are excited about. So far it’s been missing.
That said, I went to some very good breakout sessions yesterday. This is the “other reason” to go to conferences like PDC and in this case PDC has delivered the goods. I want sessions that “hurt my brain” and make me think about how approach programming problems and two of the sessions did exactly that.
First breakout was Future Directions of C# and VB. Luca Bolognese is a disarmingly charming young Italian with a thick accent and a great sense of humor. He wowed everyone at last year’s F# presentation. I attended this session because of the speaker and he delivered the goods. The most interesting bit of news here is a new use for the “yield” keyword. Although experimental, the idea is to yield control of a thread during async operations. It’s purpose is to resolve the ”many threads not enough cores issue” for parallel processing. I’m thinking we’ll use it in our current project when it becomes available.
Next came ASP.NET Futures. There are just so many cool things that are happening in ASP.NET that one presentation really can’t cover it. My favorite, ActiveRecord Integration. And not just with Entity Framework but other data providers. It even sports a “code first” model where you write the classes and just run. The framework creates and wires up a database and you’re off and running. Very nice.
Microsoft ASP.NET 4 Core Runtime for Web Developers. Again, I’m just blown away at the amount of “new stuff” coming in ASP.NET 4. This session focused on new tooling to allow better management of server resources. Frankly, much of it was “over my head” but then that’s sort of the point. Perhaps most interesting is that there are new tools to help find the “bad application” in an app pool that is running multiple applications. If you ever have encountered this problem (I have) you’ll really appreciate this new tooling.
Manycore and the Microsoft .NET Framework 4: A Match Made in Microsoft Visual Studio 2010. Usually by the end of the day I’m burned out and the last session can be a dud for that reason alone. Not this time. I suspect this will be the best breakout session (for me at least) of the conference. I can’t do any justice to it with a summary. Just spend an hour and watch it. It’s that good.
I can never seem to remember the format strings for numbers in .NET. There are several cheat sheets available but the one that works best for me is the examples page in the Microsoft documentation.
| Format | Culture | Data type | Value | Output |
| C | en-US | Double | 12345.6789 | $12,345.68 |
| C | de-DE | Double | 12345.678 | 12.345,68 DM |
| D | en-US | Int32 | 12345 | 12345 |
| D8 | en-US | Int32 | 12345 | 00012345 |
| E | en-US | Double | 12345.6789 | 1.234568E+004 |
| E10 | en-US | Double | 12345.6789 | 1.2345678900E+004 |
| E | fr-FR | Double | 12345.6789 | 1,234568E+004 |
| e4 | en-US | Double | 12345.6789 | 1.2346e+004 |
| F | en-US | Double | 12345.6789 | 12345.68 |
| F | es-ES | Double | 12345.6789 | 12345,68 |
| F0 | en-US | Double | 12345.6789 | 123456 |
| F6 | en-US | Double | 12345.6789 | 12345.678900 |
| G | en-US | Double | 12345.6789 | 12345.6789 |
| G7 | en-US | Double | 12345.6789 | 12345.68 |
| G | en-US | Double | 0.0000023 | 2.3E-6 |
| G | en-US | Double | 0.0023 | 0.0023 |
| G2 | en-US | Double | 1234 | 1.2E3 |
| G | en-US | Double | Math.PI | 3.14159265358979 |
| N | en-US | Double | 12345.6789 | 12,345.68 |
| N | sv-SE | Double | 12345.6789 | 12 345,68 |
| N4 | en-US | Double | 123456789 | 123,456,789.0000 |
| P | en-US | Double | .126 | 12.60 % |
| r | en-US | Double | Math.PI | 3.141592653589793 |
| x | en-US | Int32 | 0x2c45e | 2c45e |
| X | en-US | Int32 | 0x2c45e | 2C45E |
| X8 | en-US | Int32 | 0x2c45e | 0002C45E |
| x | en-US | Int32 | 123456789 | 75bcd15 |
This gets me about 90% of my numeric formatting needs and there are links to custom format strings for when the standard ones won’t suffice. Bookmark the MSDN page
here.
previous | next
powered by Bloget™