Theme Graphic
Theme Graphic

The Official Programmer's Heaven Blog

The blog where the Programmer's Heaven team post stuff.

Subscribe

Author

Often knowledgable, sometimes wise, occasionally funny. The Programmer's Heaven blog team post about a whole range of topics, from practical advice on concurrency control to introductions to lesser known concepts such as functional programming. Don't forget to comment on the posts and let them know what you think, like and hate!

Archive

Tags

Posted on Tuesday, April 01, 2008 at 7:17 AM

When Linq and ref Parameters Meet

It's fair to say that I'm a pretty heavy user of Linq. You'll find uses of it scattered across my code, from the obvious (using DLinq to query a database) to the slightly more exotic (writing queries over collections obtained from classes in System.Reflection). Linq often allows you to express a problem very neatly, resulting in compact, readable code. It also factors out the application of operations and leaves you to worry about the operations themselves, likely decreasing bugs.

Fixing A Bug

Today I ran across some code that took a parameter, then used it in a Linq query. Omitting the clutter, it looked something like this:
public void Lookup(string URL, ref int ID, ref int Status)
{
    // ...stuff...
    var Result = from D in DB.Datas
                 where D.URL == URL
                 select D;
    // ...more stuff...
}
...
Comments: 3 Tags: .NET, C# 3.0, Linq

Posted on Thursday, January 31, 2008 at 4:28 AM

Divvy up my list? Aye!

I wasn't born in Yorkshire, but I spent most of my childhood growing up there. Yorkshire, a large county in the north east of England, has its own collection of slang, not least including the word "aye", which it appears is appropriate in response to pretty much any situation. Another slang phrase is "divvy up". Basically, this just means to divide a bunch of things up somehow.

These days, I spend a lot of my time writing C#. If I'm dealing with a bunch of things in C#, I'll usually store them in a generic List collection, or some other collection. This got me thinking: how can I divvy up a List in C# into multiple Lists? And that's when I decided to implement the Divvy extension method.

What we're aiming for

Suppose we have a list of scores:
var Scores = new List<int>()
    { 87, 32, 45, 60, 91, 10, 58, 77, 66, 71 };
...

Posted on Tuesday, January 22, 2008 at 7:09 AM

Higher Order Programming Is Easy!

Higher Order Programming is one of those things that to many people sounds weird, magical, mysterious or just too hard for them to be able to do. It's not. If you have ever passed a function or method as a parameter to another function or method, then you have done higher order programming. If you have ever used a function pointer in C or a delegate in C# or some kind of callback mechanism, then you have done higher order programming.

Define it!

We are all used to writing code that takes parameters. We do it whenever we write subroutines, functions or methods. Normally these parameters are data. In higher order programming, one or more of these parameters is code rather than data. That is, you can pass code, functions and/or methods around, just as you can pass data around. That's all there is to it.

Show me an example

Let's look at C#, because the syntax will not be too unusual to programmers in many languages. Suppose we have a List of scores for a test...

Posted on Wednesday, December 12, 2007 at 5:12 AM

C# 3.0 Part 4: Linq

The final part of our C# 3.0 series is about Linq - Language Integrated Query.

Learn:
  • What declarative programming is
  • How to write Linq queries
  • How to use ordering, joins, groups and query continuations
  • What DLinq and XLinq are
Read it now!
Comments: 0 Tags: C# 3.0, Linq

Posted on Thursday, December 06, 2007 at 1:27 AM

C# 3.0 Part 3: Initializers & Anonymous Types

The third article in our C# 3.0 series covers the new features that will help you to build data structures with less and more readable code.

The article covers:
  • Object initializers
  • Collection initializers
  • Anonymous type is
  • Type equivalence of anonymous types
Check it out.

Posted on Tuesday, November 27, 2007 at 9:02 AM

C# 3.0 Part 2: Extension Methods & Lambdas

The second part of our C# 3.0 series is here, covering extension methods and lambda expressions. Learn:
  • What an extension method is
  • How to write extension methods
  • The new lambda expression syntax
  • To use the higher order programming paradigm
Go to the article!

Posted on Wednesday, November 21, 2007 at 9:31 AM

Learn C# 3.0 With Our New Series!

This week we are starting a brand new four part series, covering the new features of C# 3.0! The first article of the series covers type inference. You'll learn:
  • What is type inference anyway?
  • How can you take advantage of it?
  • What does the new "var" keyword do?
  • Is this at all related to Variant types in Visual Basic?
  • Will using this hurt the performance of your programs at runtime?
Check out the article!
Comments: 2 Tags: .NET, C#, C# 3.0, types

 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.