Why has a lambda with no capture changed from a static in C# 5 to an instance method in C# 6?

Roslyn (the C# compiler used by VS 2015) changed all lambda methods to non-static methods, whether they capture variables or not. See Delegate caching behavior changes in Roslyn. As I explain, this is an allowed behavior because anonymous methods (like those at issue here) that don’t capture variables have fewer lifetime requirements than those that … Read more

Delegate caching behavior changes in Roslyn

Yes. The most important part is that the method containing lambda implementation is now an instance method. You can see a delegate as a middleman receiving an instance call through Invoke and dispatching that call according to the calling convention of the implementing method. Note that there are platform ABI requirements that specify how arguments … Read more

ReSharper: setting C# language level for Solution

I added below settings in .sln.DotSettings <s:String x:Key=”/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue”>CSharp50</s:String> This line was added to .csproj.DotSettings when I tried to disable c#6 for a particular project. After adding this line in .sln.DotSettings resharper is reporting an error whenever I am trying to use c# 6.0 feature.

Operator ‘?’ cannot be applied to operand of type ‘T’

Since not everything can be null, you have to narrow down T to be something nullable (aka an object). Structs can’t be null, and neither can enums. Adding a where on class does fix the issue: public abstract class Feature<T> where T : class So why doesn’t it just work? Invoke() yields T. If GetValue … Read more

nameof with Generics

I would expect some details about the type parameters From the design docs: Result of nameof. The result of nameof depends on the symbols that its argument bound to: One or more members: if all members have the same metadata name then the result of nameof is that name; otherwise it is an error “This … Read more

What benefit does the new “Exception filter” feature provide?

The Exception Filters feature in C# 6.0 provides various benefits. Here’s an explanation of some (ordered by my perceived importance) Feature Parity – Exception filters were already implemented in the IL level and the other .Net languages (VB.Net & F#)[1] and as part of building the new compiler for C# and VB.Net (project “Roslyn”) many … Read more

nameof with generic types

This is expected. According to the documentation, your expression is disallowed, because it refers to an unbound generic type: Because the argument needs to be an expression syntactically, there are many things disallowed that are not useful to list. The following are worth mentioning that produce errors: predefined types (for example, int or void), nullable … Read more

tech