score:3
The standard Zip
method allows you to write something like (using C#):
from t in first.Zip(second, (f, s) => new { First = f, Second = s }
select ... t.First ... t.Second;
I think this should be readable enough. Your question seems to suggest that you'd like to be able to create your own keyword e.g. zip
and extend the C# query expressions using it. This is not possible in C# or Visual Basic (but I agree it would be nice in a way).
With some effort, you can redefine what standard C# query construct does, so that join
would behave like zip
(In that case, the equals
part of the query would not be needed, so you'd have a lot of syntactic noise). Possibly, you could also redefine what from
clause. I didn't try it, but I believe you could get something like:
from f in first.Zip()
from s in second.AddToZip()
from t in second.AddToZip()
select ... f ... s ... t ...;
I wrote an article that describes how to do this redefining for the group by
clause (Using custom grouping operator in LINQ), so this can give you an idea how this can be done.
(But honestly, I think that the standard Zip
method should be fine. The redefinition of operators is quite subtle. The group by
example may be more appealing because grouping using method is uglier, but even that is on the edge...)
Source: stackoverflow.com
Related Query
- Can you zip or use a custom join operator in non-expression linq?
- How can I use Linq expression for Join with GroupBy in EF Core 3.1
- Can LINQ expression use LEFT JOIN or default to null if item isn't found?
- Can you use a List to configure a selector in LINQ join query?
- How can i use Linq expression for Join on multiple table in EF Core 3.1
- Can you use LINQ types and extension methods in IronPython?
- How can you do custom sorting in LINQ with null always on the end?
- Can you reverse order a string in one line with LINQ or a LAMBDA expression
- How can you update a Linq Expression with additional parameters?
- How can I use Left join in linq that we use in sql?
- Can i use join with let in linq - c#
- How can I switch that code to use LINQ
- Can you use linq to see if two IEnumerables of data contain any common entries?
- How can I code an outer join using LINQ and EF6?
- How to use AND operator in LINQ Join
- Can you use LINQ extension method operators in an ASP.NET databinding expression?
- Can you use LINQ with in memory objects rather than SQL Server queries to improve performance?
- Can't use ternary operator to assign Linq expression
- Can you use LINQ or lambdas to perform matrix operations?
- Can you convert this Linq statement into Lambda without using join statements?
- How can I use Linq to join between objects and entities?
- How can you use LINQ to find Azure AD users with specific licenses using the Azure AD Graph API Client Library 2.0
- What would it take to create a C# compilation error, when you use custom methods where Expression is expected?
- How can you use LINQ to cast from a collection of base class objects to a filtered list of their respective subclasses?
- Using Linq to build a graph class; can you make this code look better?
- How can you use Linq result with RDLC report?
- Can I use LINQ to do a join on an IQueryable from SQL Server?
- Can I use a LINQ IEnumerable result as the data source for a Gtk.TreeView?
- Can I Use The Same Linq Code to Query for Different Conditions?
- How can I use a Linq expression using reflection?
More Query from same tag
- Using LINQ to count values in a multiple join
- IQueryable and Count
- Linq query to fill a list in a nested class receiving an error
- Linq select top 1 name of a highest score group
- How to compare two tables data and show only matched data in drop down list
- How do I create a linq query that gets everything but a specific value
- EntityFramework calling scaler function throws Must declare the scalar variable
- How to cast a list of a base type to list of the derived type
- How to remove time portion from Nullable<DateTime> in LINQ
- Linq query with multiple GroupBy
- The entity or complex type 'SJAMsSynchMetroModel.tblActionItem' cannot be constructed in a LINQ to Entities query
- LINQ query with group by and ascending ordering not working
- Unable to filter on Date fields in MongoDB using C# Driver
- How can I add more than 2 conditions to the LlNQ where clause?
- System.Data.Entity.QueryableExtensions.Include : Object reference not set to an instance
- How to query a stored procedure object with Linq
- Select all messages but not if the subject id is the same
- Getting error in LINQ query to sqlite
- Linq to entities syntax help, when having two tables
- How can I query a database with LINQ when the column is a number but I have a string in the WHERE?
- Group Data from SQL to show in WPF Tree View with Multiple Levels
- LINQ-to-Entities null conditional on navigation property on anonymous class
- struggling with linq query for distinct results
- Join all the sublists together and grab the first one
- Return Count from Netflix oData Service When the LINQ Count() Method Doesn't Work
- How do I add an xml file to my project?
- Enumeration yielded no results
- Only primitive types ('such as Int32, String, and Guid') are supported in this context when I try updating my viewmodel
- Linq to sql alias fails
- Query always returns all records