C# feature request: implement interfaces on anonymous types

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

    I have used in Java the Amonimous Class through the "new IFoo(){...}" sintax and it's practical and easy when you have to quick implement a simple interface.

    As a sample it would be nice to implement IDisposable this way on a legacy object used just one time instead of deriving a new class to implement it.

提交回复
热议问题