Ever come across a situation where you wanted to find how many of a similar object you had in a list?
Sample code: All of the code used for this example is located on GitHub here https://github.com/objectatrest/BlogCode/tree/master/LINQ_in_a_blink/LinqInABlink
In SQL it would look something like this:
And you would get the result
Well it’s pretty easy to query a collection of objects using LINQ in a similar way:
Which could print out to the console as
We can extend it to only include those that have more than one occurrence of the grouping.
The first video I watched was “Beyond design: Creating positive user experiences” from Google IO 2010 tech talks (http://code.google.com/events/io/2010/sessions/beyond-design-user-experience.html). I was really hoping for more from this presentation. Don’t get me wrong, the information was useful and the examples were well presented, however, the title was a little misleading. The basic principles they discussed were useful but they lacked a certain depth. The whole presentation took on an aura of Web 2.0 design practices. We get it – make your 404 page have a funny image and text like “we haz errorz. lolz”. I think there are many companies out there that should take the UI advice to heart. In that respect the presentation seemed to be aimed more at managers than UI devs or programmers. I can’t say I recommend the presentation unless you are trying to convince your manager that there is more to UI design than what message to put in the alert box. Unfortunately most companies don’t allow for the level of UI polish that the presenters are calling for.
Some of the technologies for measuring web site performance mentioned were:
- Yahoo YSlow
- Google Page speed
Another service they mentioned was getsatisfaction.com. I had never heard of it but the idea of a hosted support system where power users could act as level one support sounds pretty interesting. The idea is especially interesting for micro-ISVs and microprenuers.
God is in the tech specs
The second video, “LINQ – Beyond Queries” (http://channel9.msdn.com/posts/matthijs/LINQ-Beyond-Queries-by-Scott-Allen/) was a much more technical presentation focusing on the language features that make much of LINQ possible in .NET. It provided a concise overview of the new(ish) language features like extension methods, anonymous delegates, Func, and Expression that make LINQ possible and can be used to enrich the C# programming model.
The presentation material wasn’t new to me since I had read C# In Depth but it did provide a reminder of some of the more integral technologies that make up LINQ. What was more interesting than the technologies involved (blasphemy!) was the possible applications of the technology. Extension methods provide an interesting way to create a fluent interface that could appear/disappear (from Intellisense) by adding/removing a using statement.
The other interesting concept was using LINQ To Objects to implement some of the functionality of (in this case) a flowchart class. The example code in the presentation showed what was one of the first examples I had seen of using LINQ to do more than simple set operations.