Is there a difference in the declaration of lambda expressions between the .NET Framework and .NET Core?
The following expressions compiles in .NET Core:
var lastShift = timeline.Appointments
.OfType<DriverShiftAppointment>()
.SelectMany(x => x.Activities.Where(x => !x.IsTheoretical))
.OrderByDescending(x => x.Start)
.FirstOrDefault();
But not in the .NET framework.
The problem in this expression is the following part
.SelectMany(x => x.Activities.Where(x => !x.IsTheoretical))
where x
is declared twice (SelectMany
and Where
).
This is the error in the .NET Framework:
A local or parameter named 'x' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
.NET framework
Reproducable example:
public class DemoClass
{
public IList<int> Numbers { get; set; } = new List<int>();
}
class Program
{
static void Main(string[] args)
{
var lst = new List<DemoClass>
{
new DemoClass
{
Numbers = new List<int>{ 1, 2, 3, 4, 5, 6, 7, 8 }
},
new DemoClass
{
Numbers = new List<int>{ 1, 2, 3, 4, 5, 6, 7, 8 }
},
new DemoClass
{
Numbers = new List<int>{ 1, 2, 3, 4, 5, 6, 7, 8 }
}
};
var result = lst.SelectMany(x => x.Numbers.Where(x => x % 2 == 0))
.OrderByDescending(x => x);
Console.WriteLine("Hello World!");
}
}
NET Framework is a platform for . NET applications on Windows whereas, NET Core is the latest version of the . NET Framework which is a cross-platform and open-source framework optimized for modern app needs and developer workflows.
Net Framework is used for the development of both desktop and web applications as well as it supports windows forms and WPF applications. . NET Core is packaged and installed independently of the underlying operating system as it is cross-platform.
You use a lambda expression to create an anonymous function. Use the lambda declaration operator => to separate the lambda's parameter list from its body. A lambda expression can be of any of the following two forms: Expression lambda that has an expression as its body: C# Copy.
NET Core is a new version of. NET Framework, which is a free, open-source, general-purpose development platform maintained by Microsoft. It is a cross-platform framework that runs on Windows, macOS, and Linux operating systems.
To put it simple .NET Core is the new cross-platform and fully open source version of .NET (.NET Framework isn't cross-platform nor is it open source) Show activity on this post. The .NET framework is a software development framework from Microsoft.
Windows Forms and WPF applications are very well supported. .Net Core focuses more on Web, Windows Mobile, and Windows Store applications. Currently, it does not support Desktop application development. .Net Framework is packaged as a whole.
The current version of .NET Framework, 4.8, is supposed to be the last version of .NET Framework. There will be no more new versions of .NET Framework planned in the future. .NET Core Advantages. If you’re building a new application and have a choice between .NET Core and .NET Framework, .NET Core is the way to go.
.Net Framework is used for the development of both desktop and web applications as well as it supports windows forms and WPF applications. .NET Core is packaged and installed independently of the underlying operating system as it is cross-platform.
It is telling you that problem is this line:
.SelectMany(x => x.Activities.Where(x => !x.IsTheoretical))
Using the x twice confuses it, it is ambiguous, try this:
.SelectMany(x => x.Activities.Where(y => !y.IsTheoretical))
But you are right, it compiles in core but not framework. It looks to be like this: https://github.com/dotnet/roslyn/issues/38377. Reading that link, it looks like this is a change in C# 8.0, and core is targeting 8.0 while framework is targeting 7.2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With