C# in Depth

Cover of C# in Depth
Order now (3rd edition)

Additional (and inconsequential) restriction on implicit typing

Chapter 8: Cutting fluff with a smart compiler: 8.2.2

Created: 3/3/2008
Last updated: 3/3/2008

The following method call and assignment is legal. Insane, but legal.

int j = M(j=10);

It has the semantics of this code:

int j;
int temp;
temp = (j = 10);
j = M(temp);

Okay, fair enough - hopefully most readers know that code like this is a recipe for disaster. However, let's try adding implicit typing to the mix:

var j = M(j=10);

How do we find out the type of j? We look at the return type of M.
How do we work out which overload of M so use? We look at the type of j.
In short, there's a chicken and egg problem, so this is declared to be illegal.