Where are const parameters?

Development Comments

I'm programming in C# for about 18 month by now, and I really like it. However, what I'm missing about C# are constant parameters.

In C++ you can declare parameters as const, so the called method cannot change it. It's kind of a contract. If the method signature says, a parameter is constant, it won't change it.

AFAIK that's not possible in C#. Whenever you call a method with a parameter which is a reference-type, that method is capable to change it.

One possible solution is shown in following sample:

public interface IFoo
    int Param {get; }

public class Foo : IFoo
    private int param;
    public int Param
        get { return param; }
        set { param = value; }

public class MainClass
    private static void Bar(IFoo foo)
        foo.Param = 42;
    public static void Main()
        Foo foo = new Foo();

Our object we want to forward to our method as const is of type Foo. However, this class implements the IFoo interface. This interface just defines getter functions, so it is somewhat read-only. The method Bar just takes a parameter of the interface type. Therefore, it is not able to change the concrete Foo object.

Aynway, forget what I've said. That's just a nasty work-around. I don't want to implement a special interface for each of my classes soleley because I need a const parameter. Do you?

Finally, I will return to the opening question: Why does C# do not support const parameters? I hope Brad Abrams or someone else will read and answer this question. (BTW, does the MSIL? At least it supports default parameters, which C# doesn't)

Moving this site

Site news Comments

I know I'm a geek. These pages are hosted on my server at home. It's a recycled Athlon XP 1800+ running Windows Server 2003 incl IIS 6.0, MS SQL 2000 and MS Exchange 2003. It's connected via T-DSL (768/128 KBit/s).

Though this is a geekish set-up, I'm thinking about changed that for several reasons:

  1. Economics Because this machine is hosting my pages and running the mail server, it is running 24/7. How much am I at home at my machine? Well, about 3 hours in average. Plus it's a machine I cannot use for anything else.
  2. Noise The server is the loudest of all my machines. Of course I could tweak it by exchanging the fans etc, but I'm too lazy... Blushing
  3. My girl friend needs a PC She moved in two month ago, and she only has my old Celeron w/400 MHz I gave her some time ago. SHe needs her own machine, but since she just started in her job, she doesn't have the money.
  4. Bandwidth While 768KBit/s downstream is fully sufficient for browsing and downloading some MSDN packages every now and then, 128KBit/s upstream is quite restrictive for serving pages.

Therefore, I decided to move my site to a dedicated hosting service. I've already chosen WebHost4Life cause of the many credits I've read about them. However, what is left is a decent domain name... Expressionless

Self-Installing .NET Windows Service

Development Comments

Did you ever write a .NET Windows service? What I really dislike about it is that though the framework provides the System.ServiceProcess.ServiceInstaller class, you still have to use the external installutil tool.

Well, at least until today.

After some googling I found Craig Andera's article HowTo: Write a Self-Installing Service. Only a few lines of code are needed to get your service registering itself. Cool Awesome, Craig.

Why didn't Microsoft document that way? (Ok, they doc'd TransactedInstaller, but if you don't know where to search... sigh)

Did you ever right-click the Explorer's caption icon?

Software Comments

Well, I didn't until Raymond Chen posted following top today:

In Explorer, you can right-click the icon in the caption to get the context menu for the folder you are viewing. (Very handy for "Search" or "Command Prompt Here".) Apparently enough enough people realize this. In Windows 95, we tried to make it so most icons on the screen did something interesting when you right-clicked them.