C#中的继承和实现之间有什么区别 [英] What is the difference between inherits and implements in C#

查看:145
本文介绍了C#中的继承和实现之间有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

public class HitController : MonoBehaviour, ICentroidHitListener

我的理解方式。 HitController继承自MonoBehaviour,并实现了ICentroidHitListener中的方法。

The way I understand it. HitController inherits from MonoBehaviour and implements the methods in the ICentroidHitListener.

但是如果我只希望它仅实现ICentroidListener中的方法,该如何编码呢?我是否可以这样编码:

But how can I code this if I just want it only to implement the methods in the ICentroidListener? Do I code it like this:

public class HitController : ICentroidHitListener

在这种情况下,看来HitController继承自ICentroidHitListener

In which case that looks like HitController inherits from ICentroidHitListener

推荐答案

如果是接口,则实现该接口。如果是类,则将从该类继承。

If it's an interface, : implements the interface. If it's a class, : inherits from the class.

因此 HitController:ICentroidHitListener 是正确的。

这篇关于C#中的继承和实现之间有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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