Named arguments, optional arguments, and default values

C# 4.0 introduces the concept of optional parameter values into the language. Now, this has been a controversial subject in the past, and we have had many requests for the feature, but have traditionally stayed away from it. So, why now? Well, before we get into the philosophy of why we decided to add it…

30

Dynamic in C#

The other day I was playing around with some office code, and I found myself writing a lot of code much like the following sample that Anders used at his PDC talk: static void Main(string[] args) { var xl = new Excel.Application(); ((Excel.Range)xl.Cells[1, 1]).Value2 = "Process Name"; ((Excel.Range)xl.Cells[1, 2]).Value2 = "Memory Usage"; } As you…

23

Dynamic in C# VI: What dynamic does NOT do

As I mentioned last time, there are a few gotchas that we’ll need to look at in order to get a full understanding of the dynamic feature and its capabilities. Today we’ll take a look at some of those limitations. As we go along, I’ll try to shed some insights as to how the decision…

15

Dynamic in C# II: Basics

Last time, we began to dive into dynamic binding in C# and what happens through the pipeline. This time, we’ll take a simple scenario and pick apart the details of what happens under the covers, both during compile time and runtime. We can break down what the compiler does into three parts: type and member…

15

COM Interop in C# 4.0

Wow, it’s been a while since I’ve last posted! Don’t worry, I’m still alive and kickin’, and we’re still workin’ on cool stuff for y’all to use. Let’s take a bit of a recap of how far we’ve come. We’ve chatted about dynamic binding in C# and how that all plays in with the DLR,…

12

Local variable scoping in C#

In my previous post, Compiler-generated scopes for local variable declarations, I briefly touched on the issue of multiple meanings applied to the same name. In this post, I’ll aim to flush out the compiler’s rules with regards to binding names in their local scopes. Simple name resolution First, lets recall the spec’s definition of simple…

7

Dynamic in C# IV: The Phantom Method

Yes, this does sound like a Star Wars movie, but no, I’m not a Star Wars geek that just likes to pull lines from my favorite movies (though I rather enjoyed Star Wars). This post will deal with what we’ve coined "the phantom method". It’s the method that the static compiler will bind to during…

6

Named arguments and overload resolution

Last time we talked about the basics of named arguments, optional arguments, and default values. From here on out, I’m just going to refer to the whole feature group as “named and optional arguments” – it’s just too much typing otherwise (we actually just refer to the feature as N&O internally). Let’s now dive a…

6

Compiler-generated scopes for local variable declarations

I was tasked with understanding and fixing a bug on error reporting with foreach iteration variables the other day, and it got me thinking about local variable scoping rules in C# in general. First, the bug. The Bug Consider the following code: class C{ static void Main(string[] args) { foreach (int myCollection in myCollection) {…

6

generic method substitutions and unification

It’s been a while since I’ve last written – my apologies. We’ve been hard at work figuring out what the next release of C# will look like, and I’m happy to say that I’m very excited about what we’re working on. Great minds are at work figuring out things like integration of C# with the…

6