Reflector alternatives

February 18, 2011 10:18
I have to break up my silence to send a beam of hate to software terrorists at RedGate management, who recently decided to charge for Reflector, an amazing tool they took over from Lutz Roeder in August 2008. Despite the original promises to keep the app free, Reflector7 is a paid only application and - lo and behold - the previous versions will cease to work from the end of February 2011. 

What a damn shame. 

Static initializers vs Static constructors

December 27, 2009 18:40
class One
    private static string me = "Am I different?";
class Two
    private static string me;
    static Two() { me = "Am I different?"; }

There's a certain confusion around static constructors. Why should we use them instead of static initializers? Any difference between the two samples above?

The rule of thumb is simple. If you want to control the time when CLR would initialize static fields, add the static constructor. If you don't care - skip it and use static initializers.


Why C# named parameters use colons

August 9, 2009 19:14

With the advent of VS2010, there's an explosion of interest around the new features of C#4.

Named parameters.

That's a cool one.  Look at the code below and note that without checking with the signature you can't really tell where's the title and where's the message:

public void SendMessage(string title, string message) { ... }
SendMessage("foo", "boo"); //that's how you call it

And look at the C#4 variant -
now it's much better, eh?

SendMessage(title: "foo", message: "boo");


Disposing a DataSet: a play in two acts

May 17, 2009 16:22

Act I. Development office hall. Two developers, Кастусь and Пятрусь, standing near the coffee machine[1]. Late spring afternoon.

Hey man, do you think it's necesssary to call Dispose on datasets?

П: Sure - everything that implements IDisposable needs to be explicitly disposed. Thus you release the unmanaged resources you're probably holding.

K: (exultedly) Fair enough - but
DataSet doesn't actually implement IDisposable! When you dispose a dataset you call Dispose on its parent, MarshalByValueComponent. And that guy has only managed dispose logic:

protected virtual void Dispose(bool disposing)
    if (disposing) {
    //some managed disposing code here


Enums turmoil

May 3, 2009 20:12

Do you think enums are simple? Well, they are not. Look at the following code

public enum Price
    Inexpensive = Cheap
public static void Main()

Ok so I hear you saying, "It will print Cheap". Cool stuff. You're right! If multiple enum members share the same value, the "main" member acts as a source for ToString. Now we move on - I will just add a few more members.

Has shutdown started?

April 5, 2009 21:40

Salutary static adjunct for class declarations was introduced in C#2, aimed to solve the whole bunch of issues.

Previously, in order to set up a container of static methods you had to do some tricks while declaring that class.

  • First off, since it's useless to create an instance of such a class, you would create a private constructor that could never be called from the outside.
  • Then you would mark the class sealed so that nobody could inherit from it.
  • And then you would start adding your static methods, properties, etc.

Apparently there are few problems with this approach. More...

A genealogy tour in .NET: lady

March 8, 2009 20:00
To bring up a lady, start from her grandmother.
Eric Berne.

Anonymous types are nice since you write less code. You don't declare a class, and don't put its name when you create it. However, using them anywhere outside small Linq-like filterings is stultifying and dangerous (think about ASP.NET MVC here).  

But species transform themselves generation after generation, and so do software artifacts. As a corollary of this axiom, anonymous types of .NET 3.5 are about to give birth to another abstraction of .NET 4.0 [1]. Ladies and gentlemen, please make her feel welcome: Tuple, The Lady!

A genealogy tour in .NET: mother.

February 22, 2009 17:16

A lady can become a lady only if her mother has teached her everything a proper lady should know.  Obviously the mother should learn that stuff from grandparents.

In this context, grandmother is Generics and grandfather is Linq. Surprisingly enough, they engendered a wacky abstraction of Anonymous Types, a great facilitator of data filtering. They teached it how to stroll, how to smile and how to say "no" politely.

A genealogy tour in .NET: grandmother.

February 15, 2009 17:13
To bring up a lady, start from her grandmother.
Eric Berne.

Perhaps not a precise citation, but you get the idea. People take their habits and attitudes from their parents, while the parents imitate their own parents and so on. Inexplicably, this sort of upbringing can be
retraced in C# as well.

Far-fetched? Not more than anything else you'd try to compare to software development.

Waltzing Lambdas

November 2, 2008 11:00

Microsoft Visual Studio 2010 and .NET 4.0 is available for download [1]. You probably know that but anyway. We can touch something real, more than a year prior to the actual release! A lot of room for MS to fix bugs and adapt to community requests as Tom Waits sings, the quality goes in before the name goes on, eh?

The flip side of this event is that, yes, we still have some time to catch up with the existing language features of .NET.

My hobbyhorse.

It's easy to get amazed with something new and shiny while overlooking the usual things that yet have a lot of unused power. So let's talk about lambda expressions and their practical use.