Visual C# Breaking Changes in Visual Studio 2012
The following table lists changes in Visual C# in Visual Studio 2012 that might either prevent an application that was created in Visual C# in Visual Studio 2010 from compiling or change the run-time behavior of such an application.
Category |
Issue |
Description |
---|---|---|
Lambda expressions |
You can use the iteration variable of a foreach statement in a lambda expression that’s contained in the body of the loop. |
The use of a foreach iteration variable in a nested lambda expression no longer produces unexpected results. The following example uses the variable word in a lambda expression.
|
LINQ expressions |
You can use the iteration variable of a foreach statement in a LINQ expression that’s contained in the body of the loop. |
The use of a foreach iteration variable in a LINQ expression no longer produces unexpected results. The following example uses the variable number in a LINQ query.
|
Named arguments |
Side effects from named and positional arguments in a method call now occur from left to right in the argument list. |
Side effects from named and positional arguments that are combined in a method call are now produced from left to right in the calling statement's argument list. In the following example, TestMethod is called by using a combination of named and positional arguments in different orders.
|
Overload resolution |
Overload resolution has been improved for calls that use named arguments to access methods that contain params parameters. |
When more than one resolution candidate is found, overload resolution prefers the most specific type match for named arguments. Parameters for which arguments aren’t required or provided in the call are considered only when the type matches in overload candidates are equally good. In the following example, string is a better type than object for p2. Therefore, the version of ExampleMethod in which parameter p2 is defined as a string should be chosen, even though it has a third params parameter.
|
Overload resolution |
Overload resolution is improved for calls where the algorithm must choose between a Func<object> parameter and a Func parameter that has a different type parameter (e.g., string or int?) for a Func<dynamic> argument. |
In the following example, the call to CandidateMethod that sends a Func<dynamic> argument has two resolution candidates. The corresponding parameter in one of the candidates is Func<object>, and the corresponding parameter in the other is Func<string>. The overload candidate that has a Func<object> parameter should be chosen because object and dynamic are considered to be equivalent. Therefore, an identity conversion exists not only between dynamic and object but also between constructed types Func<dynamic> and Func<object>.
|
See Also
Reference
Lambda Expressions (C# Programming Guide)
Concepts
Named and Optional Arguments (C# Programming Guide)