Tag: C# 3
Tip of the day: Using the null-coalescing operator over the conditional operator
I’ve recently been refactoring a lot of code that used the conditional operator and looked something like this: int someValue =...
Why should you be returning an IEnumerable
I've seen in many places where a method returns a List<T> (or IList<T> ) when it appears that it may not actually really be required, or even desirable when...
Type Inference
Type Inference is a neat feature where the C# compiler can work out itself what type a reference to an object is. While this can be used for the developer to...
Lambda cheat sheet
A while ago I wrote about all the new language features of C# 3.0 and it occurred to me that I'd left out a chunk about Lambdas. With LINQ being such an...
Monitoring change in XML data (LINQ to XML series - Part 5)
This is the 5th part in a series on LINQ to XML. In this instalment we will look at monitoring changes in XML data in the XML classes added to .NET 3.5. The...
Navigating XML (LINQ to XML series - part 4)
In my last few posts on LINQ to XML ( part 1 , part 2 and part 3 ) I've shown you a starter on navigating around XML data. In this post I'll continue to show...
Navigating XML (LINQ to XML series - Part 3)
In my last two posts I've been introducing you to the the new XML classes in .NET 3.5. In this post I'll continue that and show you some...
Crazy Extension Method
Here is an example of a crazy extension method that alters the semantics of method calling. First the extension method: public static class MyExtensions {...
Fizz-Buzz in LINQ
This just occurred to me. It is somewhat pointless, but I thought it was interesting: static void Main( string [] args) { var result = from say in Enumerable...
Getting values out of XML in .NET 3.5 (LINQ to XML series part 2)
In my last post I gave a brief introduction to some of the new XML classes available in .NET 3.5. In this post I'll continue that introduction by explaining...
Introduction to LINQ to XML
Last year I wrote about the new languages features available in C# 3.0 ( Anonymous Types , Extension Methods , Automatic Properties , A start on LINQ , Object...
Mixins in C# 3.0
This is something I've been mulling around in my head for a few days now. "Out of the box" C# 3.0 does not support mixins, but I think you can get some of the...
A start on LINQ
I was at the Microsoft MSDN Roadshow today and I got to see some of the latest technologies being demonstrated for the first time and I'm impressed. Daniel...
Anonymous Types
Anonymous Types are another new feature to the C# 3.0 compiler. To create one, just supply the new keyword without a class name, followed by the, also new,...
Automatic Properties
Continuing my look at the new features found in the C# 3.0 compiler I will look at Automatic Properties. public class Employee{ public string FirstName { get;...
Extensions Methods
There have been many times a class has needed to be extended, but the additional code just doesn't sit right on the class itself, or I don't have access to the class...
Object Initialisers (1)
Continuing with the language enhancements in C#3.0. This post presents the concept of object initailisation. Say you have a class with a default constructor...
Object Initialisers (2)
Following on from a comment left on my previous post on Object Initialisers, I decided to take a screenshot of Orcas displaying the tooltips. I...
Object Initialisers (3)
It seems that now I've got Lutz Roeder's Reflector on the case with Orcas the way object initialisers work slightly different to how I expected. As it was...
