如何在C#中将类更改为接口 [英] How to change a class to an interface in C#

查看:104
本文介绍了如何在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 an interface: Interfaces specifically cannot contain any concrete implementation of any property or method - they are purely abstract.

You can make a class abstract, 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆