C# feature request: implement interfaces on anonymous types

前端 未结 10 1546
走了就别回头了
走了就别回头了 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:11

    This wouldn't be possible currently.

    What would be the difference between this and simply making IFoo a concrete class instead? Seems like that might be the better option.

    What it would take? A new compiler and tons of checks to ensure they didn't break the other features. Personally, I think it'd just be easier to require developers to just create a concrete version of their class.

提交回复
热议问题