0

Is it possible to make two instances of two different classes which are inherited by one interface.

Is it possible to make two instances of two different classes which are inherited by one interface. And make assignment of one instance to another in some good way?

20th Apr 2021, 5:59 PM
OverHeaven
OverHeaven - avatar
2 ответов
0
If there is an interface `I`, and classes A and B inherit from I, then you can assign either of A or B to a variable of type `I`. So if you assign an instance of A to a variable of type I, then you can assign B to the same variable also. I don't know much C#, apologize in advance if the following code uses bad practises and I would be happy to be corrected by someone. But this demonstrates what I said above https://code.sololearn.com/cXS6S7R0WNE1/?ref=app
20th Apr 2021, 6:14 PM
XXX
XXX - avatar
0
Well yeah that works. Thank you
20th Apr 2021, 6:37 PM
OverHeaven
OverHeaven - avatar