Why does C# always use callvirt? – followup

I was responding in comments, but it doesn’t allow me to use links, so here’s the long version:  Judah, Yes, marking everything as virtual would have little performance impact. It would, however, be a Bad Thing. It’s #3 on my list of deadly sins…  ShayEr, cmp [exc], exc is the solution to the problem. It’s there because…

3

Updated version of my book coming…

In the spring before C# was first disclosed, I ended up, through a curious juxtaposition of events, writing a book on C# named “A Programmer’s Introduction to C#” This probably rates second on the list of “cool things I got to do while I was on the C# team” (being on the language design team…

7

What’s with those “break” statements?

One comment from my recent post was big enough to handle separately… Thomas wrote: I’ll second the break statement. Why is it really necessary? Haven’t you guys got enough feedback to acknowledge that wasn’t the brightest move? You say it is there to please the C++ developers, because they are your main target. The C++…

24

x+=x++;

Luca, who is taking over for me as C# Compiler PM, wrote this post: x+=x++; I heartily agree with him when he says “DO NOT WRITE THAT CODE”.

1

Be a language designer redux…

Thanks for all the responses to the question that I posed. The reason I posed it is that I’ve been seeing a lot of language requests coming through the MSDN feedback site, which is a good thing, but some of them are pretty obviously impractical, so I wanted to try to explore a little of…

17

Be a language designer…

I started writing a normal blog post – well, as normal as any blog post of mine ever is – and then I decided to let you do the hard work. So here’s the situation. You’re part of the C# language design team thinking about the next version of C# (ie the version after VS…

55

Conditional Attributes

There’s an extension to the conditional concept that shows up in Whidbey. It’s not in Beta1 (well, to be more correct, it doesn’t really work in beta 1), but it will be functional in beta2. If you put a conditional attribute on an attribute definition, that instructs the compiler to only place that attribute in…

7

Conditional Methods

I saw an internal post today about somebody who wanted to get rid of their #if DEBUG statements in their code, because they were ugly. That made me realize that there’s a feature that not everybody knows about, known as conditional methods. Consider the following code: using System; using System.Diagnostics; class Program {     static void…

16

Arrays inside of structures

Sometimes when doing interop, you want to have an array embedded inside of a struct. For example, something like: struct data{    int header;    int values[10];} that you either used in a call to interop, or with unsafe code to deal with an existing format – something like a network packet or a disk record. You…

13

Nested Using Statements

I got a comment on the language feature post, asking about an easier way to write:   using (StreamWriter w1 = File.CreateText(“W1”))  {      using (StreamWriter w2 = File.CreateText(“W2”))      {          // code here      }   } You can do this by writing:   using (StreamWriter w1 = File.CreateText(“W1”))  using (StreamWriter w2 = File.CreateText(“W2”))  {      // code here  }

19