SRT Solutions

Blogs

Browse by Tags

  • Duck Typing in C# 4.0

    I’ve been having fun learning the new upcoming C# 4.0 features Anders described at PDC (see video here ). One of the the more interesting areas is dynamic, and the ways you can use dynamic to support duck typing . In C# 4.0, you can create methods that take parameters that are dynamic. That means those...
    Posted to Bill Blogs in C# (Weblog) by wwagner on Tue, Nov 11 2008
  • Extension Methods and Null Arguments

    A little while ago, I did a DNR TV on C# 3.0 . During that, I talked about preserving null semantics when  you write extension methods.  I made the point that you should never test if the first parameter of an extension method is null. That’s because it breaks the semantics of member methods...
    Posted to Bill Blogs in C# (Weblog) by wwagner on Sun, Oct 26 2008
  • Euler Problem 10

    Patrick posted his solution earlier this week. I figure it was time to add mine. Also, Octavio Hernandez pointed out in the comments to problem 8 that he had discussed similar code constructs in his blog a while back. Problem 10 asks for the sum of all primes less than 2 million. It's also one line...
    Posted to Bill Blogs in C# (Weblog) by wwagner on Sun, Aug 31 2008
  • Code from Lightning Talk: Compiler Tricks

    My last Lightning Talk should how you can mix constructor calls and object initializers. It's a useful technique that can keep you from writing too much code you don't need. To see what I mean, start with this simple person class: 1: class Person 2: { 3: public string FirstName 4: { 5: get; 6...
    Posted to Bill Blogs in C# (Weblog) by wwagner on Sat, Aug 30 2008
  • Euler Problem 7

    Yes, it's true that I've been very lax in working on these problems. It's been a combination of the day job, finishing all the editing tasks on "More Effective C#", and actually trying to keep the personal life intact. The 7th problem is quite straightforward: find the 10,001st...
    Posted to Bill Blogs in C# (Weblog) by wwagner on Thu, Aug 14 2008
  • Overload Resolution on Extension Methods

    I had a question from a colleague the other day about extension methods. I'm simplifying a little, but he was looking for a way to ensure that every source file used the same set of extension methods. There is one way to enforce this, but it does have an effect on your code organization. Section...
    Posted to Bill Blogs in C# (Weblog) by wwagner on Sun, Aug 10 2008
  • A Functional Programming Q & A

    I received this question in email from one of my readers, and I thought it would be of general interest: I find myself with two arrays of the same size and I want to create a third that combines each element. What I want is something similar to var S3 = S1.foreach(S2, (s1, s2) => s1 + s2); this would...
    Posted to Bill Blogs in C# (Weblog) by wwagner on Wed, Apr 23 2008
  • Discussion on Project Euler Problem 2

    The second Euler problem asks you to find the sum of all even valued terms in the Fibonacci sequence which do not exceed 4,000,000. Let's look at the solution from the outside in. Here's the query that finds the answer: var EvenFibNumbers = (from n in Enumerable.Range(1, MAX) let value = FibonacciSequence...
    Posted to Bill Blogs in C# (Weblog) by wwagner on Thu, Mar 27 2008
  • Looking Inside C# Closures

    If you're like me, you understand new language features better when you see what the new language features generate for you. Closures in C# are no different. There's quite a bit that goes on under the covers in a C# closure. Looking at all the code that the C# 3.0 compiler generates can really...
    Posted to Bill Blogs in C# (Weblog) by wwagner on Tue, Jan 22 2008
  • Yet another use for Extension methods : Extending IComparable<T>

    I keep finding more uses for extension methods. This time it's extending IComparable<T>. The API signature for IComparable<T> has been around since the dawn of C: if the left is less than the right, return something less than 0, if left is greater than right, return something greater...
    Posted to Bill Blogs in C# (Weblog) by wwagner on Mon, Jan 7 2008

In our last colurm, we wrote about how technical mentors can benefit companies ( Ann Arbor Business Review, May 22, 2008 ). In this installment, we're...