简体   繁体   中英

C# equivalent of Java 'implements' keyword?

In Java if you were to have the statement:

public class MyClass implements LargerClass {

Would you be extending the LargerClass with more methods?

What would be the equivalent of this class definition in 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.

Thanks in advance.

public class MyClass implements LargerClass

In Java, this declares that MyClass implements the interface LargerClass ; that is, sets out implementations for the behaviours defined in LargerClass .

To inherit from another class in Java, use extends , eg

public class MyClass extends LargerClass

The C# equivalent, in both cases, is specified as

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 .

public class MyClass : LargerClass
{

}
public class MyClass : LargerClass {...}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM