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 197 views
1 answer 207 views
207 views asked Sep 11, 2020 by avibootz
1 answer 157 views
157 views asked Apr 27, 2017 by avibootz
2 answers 237 views
237 views asked Apr 25, 2017 by avibootz
1 answer 160 views
160 views asked Dec 21, 2016 by avibootz
...