C# Stumper: Why does this code not compile?

Hey folks, First off, I want to appologize for not having any activity on my blog for a while. I just got back from a wonderful 3 week vacation in Spain. Now that I’m back, rested and limber, here’s a twisted peice of C# code which is gauranteed to turn your brain inside out. Why does…

17

Many C# Questions: Switching on non-constant values.

I finally decided to play with the style settings on my blog. As you may have guessed, I’m a bit of a newbie when it comes to websites and blogging. Let me know what you think of the new look. Last weeks posting generated some great comments. Tzagotta asks:   Why are constant expressions required in…

1

Many Questions: Switch On Enum

Just a quick one this week:    Why is it that you cannot use enum constants in a switch statement’s cases without first casting them to type int?   Often you will want to use Enum constants as case labels in switch statements. Sometimes, the compiler will complain and require a cast to int on…

16

Many Questions: Generics Variance

One of the main benefits of the addition of generics to C# is the ability to easily create strongly typed collections using types in the System.Collections.Generics namespace. For example, you can create a variable of type List<int>, and the compiler will check all accesses to the variable – ensuring that only ints are added to…

7

Many Questions: general catch clause

I’m back from my course on Software Design. Now that we are starting to think about the version of C# after VS 2005 we are shining a bright light on all the ways the current compiler codebase could be better. This is the fun part of the product cycle where you get to really dig…

2

Out this week …

I’ve been out this week taking a great course on designand architecture. For those interesed in the evolution of C#, check this out  http://msdn.microsoft.com/events/pdc/ 

0

Many Questions: switch on type

I hope everyone had a good fourth of July weekend. I certainly did. I spent the weekend hiking around the Olympic peninsula with my girlfriend and capped it off watching the fireworks here in Seattle. On to our question of the week: We get a lot of requests for addditions to the C# language and today…

15

Many Questions: Protected Constructors

Well here it is, one week into my many questions series and I’m already late for the second issue. I have a good reason though, as I took a long weekend to rock climb out at Stone Hill near Eureka Montana. If you are into climbing, I highly recommend it – Stone Hill has a…

3

Many Questions: User defined conversions and Interfaces

I get a lot of questions about the rationale behind the design of the C# language. Over the next few months I’m going to try and make a point of posting a C# language design question up here every Monday. This week’s question comes from Erik Meier. I was wondering what the reason is to…

1

A Quick note on using statements in C#

Nicholas Paldino(caspershouse.com) noticed a change in the C# using statement between Beta 1 and Beta 2 of VS 2005. Here’s the full story … In V1 and V1.1, the C# compiler accepted only types implementing IDisposable in using statements. In Beta1 of Whidbey we added support for the pattern based resource types, and in Beta2 we reverted…

2