[英]'Extends' and 'Implements' Java equivalents in C#
What is the C# equivalent syntax for the following Java statement:以下 Java 语句的 C# 等效语法是什么:
public class Lion extends Animal implements Diurnal()
{
}
the inheritance could be declared like this.继承可以这样声明。
public class Lion : Animal, Diurnal
{
}
In C#
, you can inherit one base class and can be multiple Interfaces.在
C#
,可以继承一个基类,也可以是多个接口。
One more tip, if you are making an Interface
in C#, prefix it with I
.还有一个提示,如果你在 C# 中创建一个
Interface
在它前面加上I
前缀。 eg IDiurnal
例如
IDiurnal
public class Lion : Animal, // base class must go first
Diurnal // then interface(s) if any
{
}
Would look something like this:看起来像这样:
public class Lion :Animal, Diurnal {
}
Where Animal
is a class and Diurnal
is an interface .其中
Animal
是一个类,而Diurnal
是一个接口。
Please note, that according to the C# naming convention, interface has to have "I" infront of its name, so finally it should look like this:请注意,根据 C# 命名约定,接口的名称前必须有“I”,因此最终应如下所示:
public class Lion :Animal, IDiurnal {
}
In C#, there is uniform syntax for extending class and implementing interface.在 C# 中,扩展类和实现接口有统一的语法。
public class Lion : Animal, Diurnal {
}
你需要写下第一个基类像( Animal
是基类),最近的接口像as( Diurnal
是一个接口)
public class Lion : Animal, Diurnal {}
the first name after : is the extended class, after comes the implemented interfaces : 后面的名字是扩展类,后面是实现的接口
public class Lion : Animal, Diurnal
{
}
c# do not allow multiple class extension, but you can implement many interfaces c#不允许多个类扩展,但是可以实现很多接口
public class Lion : Animal, Diurnal
{
}
interface Diurnal
{
}
class Animal
{
}
Class Animal
was inherited by Lion
class.类
Animal
由Lion
类继承。 Diurnal
class is interface. Diurnal
类是接口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.