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 309 views
1 answer 304 views
304 views asked Sep 11, 2020 by avibootz
1 answer 245 views
245 views asked Apr 27, 2017 by avibootz
2 answers 337 views
337 views asked Apr 25, 2017 by avibootz
1 answer 237 views
237 views asked Dec 21, 2016 by avibootz
...