How to convert class to interface in C#

1 Answer

0 votes
using System;

interface INFC {
    void Show();
}

class Test : INFC {
    public void Show() {
        Console.WriteLine("Show()");
    }
}

class Program
{
    static void Main()
    {
        Test t = new Test();
        t.Show();

        INFC iface = t as INFC;
        if (iface != null) {
            iface.Show();
        }
    }
}



/*
run:

Show()
Show()

*/

 



answered Sep 11, 2020 by avibootz

Related questions

2 answers 303 views
1 answer 296 views
296 views asked Sep 11, 2020 by avibootz
1 answer 239 views
239 views asked Apr 27, 2017 by avibootz
2 answers 331 views
331 views asked Apr 25, 2017 by avibootz
1 answer 232 views
232 views asked Dec 21, 2016 by avibootz
...