C # - Refining the interface

I read a few questions about the interface:

<i> "An interface is a contract definition that must correspond to a class. inherits anything."

defining the difference between an interface and an abstract class, I can say:

when a class is derived from an abstract class, it is known as real inheritance. When a class uses an interface, it is not an inheritance, is it an implementation of contracts?

+3
source share
7 answers

Yes you are right. an interface is just a class contract.

note: System.Object - . - , , , , . can not ; , ().

:

interface I1
{
}
interface I2
{
}

abstract class a1
{
}
abstract class a2
{

}
class App:a1,I1,I2  //no Error
{   
static void Main(string[] args)
{       
}
}

. CLR , System.Object

       interface I1
        {
        }
        interface I2
        {
        }

        abstract class a1
        {
        }
        abstract class a2
        {

        }
        class App:a1,a2,I1,I2  //  Error
        {   
        static void Main(string[] args)
        {       
        }
        }
+3

.. ,

?

- , . , , ? ( ). , , . , . , , .

?

. , Interface. ; , , . , , . , , . # , .

, - , . , , : .

, , , . , . - , , .

+2

, ,

, .

, , , , . , , , . :

interface IA
{
    void MethodA();
}

interface IB : IA
{
    void MethodB();
}

class B : IB
{
    public void MethodA() { }
    public void MethodB() { }

}

class AB : IA, IB
{
    public void MethodA() { }
    public void MethodB() { }
}

IL B AB ( ildasm ), , , , . IB "", IA, .

+1

. , , ?

+1

, - , . . , , .

.

, .

+1

, :

, , . ; , . , , . .

, , . . , , , abstract. , virtual () overrides . - ; , .

, !

+1

. .

Simple.

, (!) .

Just redirect your brain around you and you will see that the answer was right in front of you.

0
source

Source: https://habr.com/ru/post/1719150/


All Articles