score:271
let doesn't have its own operation; it piggy-backs off of select
. you can see this if you use "reflector" to pull apart an existing dll.
it will be something like:
var result = names
.select(animalname => new { namelength = animalname.length, animalname})
.where(x=>x.namelength > 3)
.orderby(x=>x.namelength)
.select(x=>x.animalname);
score:1
about code equivalent to the 'let' keyword in chained linq extension method calls
above comment is no more valid
var x = new list<int> { 2, 3, 4, 5, 6 }.asqueryable();
(from val in x
let val1 = val
let val2 = val + 1
where val2 > val1
select val
).dump();
produces
system.collections.generic.list`1[system.int32]
.select(
val =>
new
{
val = val,
val1 = val
}
)
.select(
temp0 =>
new
{
temp0 = temp0,
val2 = (temp0.val + 1)
}
)
.where(temp1 => (temp1.val2 > temp1.temp0.val1))
.select(temp1 => temp1.temp0.val)
so multiple let
are optimized now
score:7
there is also a .let extension method in system.interactive, but its purpose is to introduce a lambda expression to be evaluated 'in-line' in a fluent expression. for instance, consider (in linqpad, say) the following expression that creates new random numbers every time it's executed:
var seq = enumerableex.generate(
new random(),
_ => true,
_ => _,
x => x.next());
to see that new random samples show up every time, consider the following
seq.zip(seq, tuple.create).take(3).dump();
which produces pairs in which the left and right are different. to produce pairs in which the left and right are always the same, do something like the following:
seq.take(3).tolist().let(xs => xs.zip(xs, tuple.create)).dump();
if we could invoke lambda expressions directly, we might write
(xs => xs.zip(xs, tuple.create))(seq.take(3).tolist()).dump();
but we can't invoke lambda expressions as if they were methods.
score:95
there's a good article here
essentially let
creates an anonymous tuple. it's equivalent to:
var result = names.select(
animal => new { animal = animal, namelength = animal.length })
.where(x => x.namelength > 3)
.orderby(y => y.namelength)
.select(z => z.animal);
Source: stackoverflow.com
Related Query
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Why the extension method of where for LINQ in this code would print out a single number while it shouldn't print anything at all?
- Linq extension method equivalent for that code in VB.NET
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- What is the equivalent of Java's Stream#Peek method in Linq C#?
- linq extension method to take elements from the end of the sequence
- LINQ: How to do JOIN using the linq extension method style on multiple fields?
- What is the C# extension methods equivalent for this Linq query?
- LINQ - Writing an extension method to get the row with maximum value for each group
- In LINQ, how do I modify an existing LINQ extension method to add a "By" selector, i.e. add Func<T> TResult to the function signature?
- Can I use the .Min() Linq extension method on a bool type?
- Is it possible to convert the result of the LINQ "Take" extension method to the original type?
- SQL equivalent of Count extension method for LINQ isn't obvious
- Why do asynchronous calls in C# need to be declared as such if the method they reside in is declared with the 'async' keyword already?
- Extension Method Limiting The Number Of Linq Results?
- Is the from keyword preferable to direct method calls in C#?
- Extension method & LINQ to Entities does not recognize the method error
- How to write this code using the Linq Extension Method-Syntax?
- How can I check the number of calls to the database in LINQ query when using .NET Core and Code First?
- Extension method (like Take()) not available for the LINQ query, Any reason why?
- Why does this linq extension method hit the database twice?
- What's the equivalent of GROUP INTO in Linq extension method?
- C# LINQ Generic Extension Method to check if sequence is the same and return it's value
- How can I make Linq extension method available for the entities?
- How to access anonymous type projected in Linq query in the next chained extension method?
- How do I correlate a Linq query extension method to its signature in the documentation?
- Why the LINQ method `Where` in my code is wrong for string[]?
- What is the use of Enumerable.Zip extension method in Linq?
- LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression
- LINQ to Entities does not recognize the method
More Query from same tag
- Error on result of linq expression (and anounymous type)
- C# WPF DataGrid setting multiple selected items programatically
- Left join on Linq?
- SubSonic 3 Linq Joining error after using CleanUp
- Linq query fine tuning
- Linq C# : Integer dbnull value how can I check it?
- Filtering or removing array objects from the DTO class object based on a condition in .net
- Expression Tree as part of a Property
- EF6 Select with Many to Many relationship
- How to get the total page of LINQ pagination
- SQL to LINQ with left join subqueries
- Add simultaneity two object depend on each other
- How to define in the lambda expression as another function in LINQ Select Method
- How to store join query data and retrieve using foreach loop from master layout page in asp.net mvc
- How to combine and update two xml files with LINQ c#
- N-way intersection of sorted enumerables
- Modify elements in list with ForEach lambda
- LINQ join statement to check if number exist in another join table
- iterating through the hierarchy of objects - C# - linq
- C# compare lists in a resource efficient way
- Linq query - use string as property?
- C# - Any clever way to get an int array from an object collection?
- Join two datatable using LINQ and get result in other datatable
- How do I get values of Linq Expression
- IQueryable methods are not resolved for dynamic query variable
- Join DataTables to get new DataTable via LINQ
- Aggregate vs. Any, for scanning objects such as IEnumerable<bool>
- Using linq to find an object which contains any values
- Group by on multiple columns and trace values which are not distinct
- Using LinQ expressions to get Date from a DateTime property