[英]C# equivalent of Java 'implements' keyword?
In Java if you were to have the statement: 在Java中,如果您要声明:
public class MyClass implements LargerClass {
Would you be extending the LargerClass with more methods? 你会用更多方法扩展LargerClass吗?
What would be the equivalent of this class definition in C#? C#中这个类定义的等价物是什么?
I ask because I am not very familiar with Java and am currently converting some Java code to C# code and this one is giving me some trouble. 我问,因为我不熟悉Java,目前正在将一些Java代码转换为C#代码,这个问题给我带来了麻烦。
Thanks in advance. 提前致谢。
public class MyClass implements LargerClass
In Java, this declares that MyClass
implements the interface LargerClass
; 在Java中,这声明
MyClass
实现了接口 LargerClass
; that is, sets out implementations for the behaviours defined in LargerClass
. 也就是说,列出了
LargerClass
定义的行为的LargerClass
。
To inherit from another class in Java, use extends
, eg 要从Java 继承另一个类,请使用
extends
,例如
public class MyClass extends LargerClass
The C# equivalent, in both cases, is specified as 在两种情况下,C#等效项都指定为
public class MyClass : LargerClass
Since this syntax doesn't make it clear whether or not LargerClass
is an interface or another class being inherited, you'll find C#/.NET developers adopt the convention that interface names are prefixed with uppercase "I", eg IEnumerable
. 由于此语法不清楚
LargerClass
是否是继承的接口或其他类,因此您会发现C#/ .NET开发人员采用接口名称以大写“I”为前缀的约定,例如IEnumerable
。
public class MyClass : LargerClass
{
}
public class MyClass : LargerClass {...}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.