如何在C#中将类更改为接口 [英] How to change a class to an interface in C#
问题描述
我有一个类,这有很多实现方法,这用于不同的解决方案以及有一个dll参考。
我需要将此类转换为接口,而不会影响使用本课程的其他解决方案
如何实现这一目标?
我的尝试:
i有一个类,这有很多实现的方法,这用于不同的解决方案以及有一个dll参考。
我需要将此类转换为接口,而不会影响使用此类的其他解决方案
如何实现此目的?
i have a class , this has many methods with implementation , this is used in diffrent solution as well by having a dll refrence.
I need to convert this Class to an interface , without impacting the other solutions which are using this class
How can i do achieve this ?
What I have tried:
i have a class , this has many methods with implementation , this is used in diffrent solution as well by having a dll refrence.
I need to convert this Class to an interface , without impacting the other solutions which are using this class
How can i do achieve this ?
推荐答案
您无法将任何实现转换为接口
:接口具体不能包含任何属性或方法的任何具体实现 - 它们纯粹是抽象的。
您可以创建一个类abstract
,这将允许实现属性和方法,但不允许多重继承。
You cannot convert any implementation to aninterface
: Interfaces specifically cannot contain any concrete implementation of any property or method - they are purely abstract.
You can make a classabstract
, which will allow implementation of properties and methods, but will not allow "multiple inheritance".
使用Visual Studio提取界面:
提取界面重构(C#) [ ^ ]
Use Visual Studio to extract an interface:
Extract Interface Refactoring (C#)[^]
这篇关于如何在C#中将类更改为接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!