Posts

Showing posts from February, 2009

Hey Compiler Team -- Make My Life Easier

The local Bellingham .NET User Group was blessed by having a speaker from the Microsoft C# compiler team visit and tell us about C# 4.0. One of the things that she kept repeating was that "fill in new feature" was done to save typing. Here is my suggestion for a language change: I do a lot of this: public class X { private int _id; public X(int id) { _id = id; } } Most of the time I have several overloads of the constructor, wouldn't it be nice if I could just write this: public class X { private int _id; public X(int _id) {} } If the compiler sees a variable in the constructor with the same names as a member variable of the class (an illegal syntax already) it would know that I want to assign the member variable automatically. The compiler already has to check for conflicts, so it is doing most of the work already. And it you didn't want this to happen, you could just change the variable name to be unique to the local an

Nullable Types And The Ternary Operator

Lately I have been wondering why this will not compile in C# 2.0 Visual Studio 2005: int? x = ({ expression } ? null : 1); The error I get is: Type of conditional expression cannot be determined because there is no implicit conversion between ' ' and 'int' I would assume that the compiler "knows" that x can be null, or any int. However, it can't cast null to an int here. Probably becuase it is evaluating the ternary expression first. This works: int? x; if ({ expression }) x = null else x = 1 Probably because it evaluates the expression first then the assignments. Anyways a work around (suggested by Andy) is: int? x = ({ expression } ? (int?)null : 1); Which really shouldn't be nessecary. {6230289B-5BEE-409e-932A-2F01FA407A92}

Hyper-V Configuration Lost With Critical Updates

Critical updates last night (Tuesday 2/10/2009) on my Windows 2008 Server with Hyper-V host operating system, caused my virtual machines not to boot. The error is: "An error occurred while attempting to change the state of the virtual machine [machinename]" '[machinename]' failed to intialize An attempt to read or update the virtual machine configuration failed. The solution to the problem is to: 1) Right click on the virtual machine in the server manager under Roles | Hyper-V | Hyper-V Manager 2) Choose Settings and write down all your settings you are going to need to re-enter them. 3) Choose Delete 4) You get a warning that the configuartion will be deleted, however not the hard drives. 5) Choose Yes. 6) Click On New From the Actions Window and Choose Virtual Machine 7) Walk through the wizard and reset up the virtual machine, when you get to the connect virtual hard disk window, choose: "Use an exisitng virtual hard disk" and select your old disk