Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# equivalent of Java 'implements' keyword?

Tags:

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.

like image 775
timmyg Avatar asked Feb 04 '09 20:02

timmyg


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.

Is C programming hard?

C is more difficult to learn than JavaScript, but it's a valuable skill to have because most programming languages are actually implemented in C. This is because C is a “machine-level” language. So learning it will teach you how a computer works and will actually make learning new languages in the future easier.

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.


2 Answers

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, e.g.

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", e.g. IEnumerable.

like image 153
Rob Avatar answered Oct 13 '22 15:10

Rob


public class MyClass : LargerClass {  } 
like image 28
David Morton Avatar answered Oct 13 '22 15:10

David Morton