Interfaces in C#?

Posted on 2006-03-31
Last Modified: 2010-04-16

i am a JAVA developer and learning now C#...

Can someone tell me if Interfaces also in C# available? If yes how i can use them?

Kind Regards Stefan
Question by:woigl
    LVL 7

    Expert Comment

    LVL 4

    Accepted Solution

    Yes. C# has Interfaces. They behave the same as in Java with two exceptions:
    1.) C# Interfaces cannot have fields/constants like in Java.
    2.) C# Interfaces do not allow for accessibility declarations (i.e. no 'public', 'private', 'protected', etc) in the interface.

    Everything else is essentially the same.

    Here are the official docs on it:

    To summarize:

    To create an interface:

    public interface IAnimal
         void Eat();
         void Sleep();  

    To implement an interface:

    public class Dog : IAnimal
         public void Eat()
             // Do some eating here

         // Explicit interface definition, does not show up on Dog's Intellisense unless you cast it explicitly to an IAnimal reference
         void IAnimal.Sleep()
              // Sleepy stuff here

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now