Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

.Net 8+ LINQ examples with EqualityComparer.Create #9851

Open
Labels
Pri3Indicates issues/PRs that are low priorityarea-System.Linq
Milestone
@AshbyGeek

Description

@AshbyGeek

in .Net 8 new class was created to allow using lambdas anywhere that IQualityComparer is used. According todotnet/runtime#101448 the reasoning was that adding lambda functionality everywhere IEqualityComparer is used would become a maintenance headache.

Unfortunately,EqualityComparer.Create is very new and not well enough known to show up on google searches or otherwise be easily discoverable.

I propose adding small example snippets that demonstrate this new functionality so that it can be more easily discovered. For example: inEnumerable.SequenceEqual(IEnumerable, IEnumerable, IEqualityComparer)

The following example demonstrates how a lambda function can be used to compare to sequences:

ProductA[]storeA={newProductA{Name="apple",Code=9},newProductA{Name="orange",Code=4}};ProductA[]storeB={newProductA{Name="apple",Code=9},newProductA{Name="orange",Code=4}};IEqualityComparer<ProductA>comparer=EqualityComparer.Create((first,second)=>first.Code==second.Code);boolequalAB=storeA.SequenceEqual(storeB,comparer);Console.WriteLine("Equal? "+equalAB);/*    This code produces the following output:    Equal? True*/

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pri3Indicates issues/PRs that are low priorityarea-System.Linq

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp