C# feature request: implement interfaces on anonymous types

前端 未结 10 1552
走了就别回头了
走了就别回头了 2021-02-19 06:57

I am wondering what it would take to make something like this work:

using System;

class Program
{
    static void Main()
    {
        var f = new IFoo { 
              


        
10条回答
  •  迷失自我
    2021-02-19 07:12

    Wouldn't this be cool. Inline anonymous class:

    List.Distinct(new IEqualityComparer() 
    { 
        public override bool Equals(Student x, Student y)
        {
            return x.Id == y.Id;
        }
    
        public override int GetHashCode(Student obj)
        {
            return obj.Id.GetHashCode();
        }
    })
    

提交回复
热议问题