Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • C# Data Types
  • C# Decision Making
  • C# Methods
  • C# Delegates
  • C# Constructors
  • C# Arrays
  • C# ArrayList
  • C# String
  • C# Tuple
  • C# Indexers
  • C# Interface
  • C# Multithreading
  • C# Exception
Open In App
Next Article:
C# Interface
Next article icon

C# Interface

Last Updated : 05 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

An interface is defined using the interface keyword, similar to a class. An Interface is a blueprint that outlines a group of methods, properties, events, or indexers that a class or struct must implement. Unlike classes, it contains only the declaration of the members. The implementation of the interface’s members will be given by a class that implements the interface implicitly or explicitly. There are some important points to remember, as mentioned below:

  • Interfaces cannot have private members.
  • By default, all the members of Interface are public and abstract.
  • The interface will always be defined with the help of the keyword interface
  • Interfaces cannot contain fields because they represent an implementation of data.
  • We can achieve multiple inheritance with the interface but not with the classes.
  • We can implement multiple interfaces in a single class separated by commas.

Example 1: Demonstrating the basic case for implementing the Interface.

C#
// Demonstrate working of Interface  using System;   interface inter1 { 	// method having only declaration  	// with no definition 	void display(); }  // Implementing inteface in Geeks class Geeks : inter1 { 	// providing the body part of function  	public void display() 	{ 		Console.WriteLine("Demonstration of interface"); 	}    	// Main Method 	public static void Main(String[] args) 	{ 		Geeks t = new Geeks(); 		t.display(); 	} } 

Output
Demonstration of interface 


Example 2: Implementation of interfaces and the use of polymorphism in C#

C#
// Using Interfaces and Polymorphism using System;  // interface declaration  interface Vehicle { 	// abstract method.  	void speedUp(int a); }  // class implements interface  class Bicycle : Vehicle { 	int speed;  	// Method increase speed  	public void speedUp(int increment) 	{ 		speed = speed + increment; 	}  	// Method check speed 	public void CheckSpeed() 	{ 		Console.WriteLine("speed: " + speed); 	} }  // class implements interface  class Bike : Vehicle { 	int speed;    	// to increase speed  	public void speedUp(int increment) 	{ 		speed = speed + increment; 	}  	public void CheckSpeed() 	{ 		Console.WriteLine("speed: " + speed); 	} }  class Geeks { 	public static void Main(String[] args) 	{ 		// creating an instance of Bicycle  		// doing some operations  		Bicycle bicycle = new Bicycle(); 		bicycle.speedUp(3);  		Console.WriteLine("Bicycle present state :"); 		bicycle.CheckSpeed();  		// creating instance of bike.  		Bike bike = new Bike(); 		bike.speedUp(4);  		Console.WriteLine("Bike present state :"); 		bike.CheckSpeed(); 	} } 

Output
Bicycle present state : speed: 3 Bike present state : speed: 4 

Advantages of Interfaces

  • Loose coupling: It is used to achieve loose coupling rather than concrete implementations, we can decouple classes and reduce interdependencies.
  • Abstraction: Interface helps to achieve full abstraction.
  • Maintainability: It helps to achieve component-based programming that can make code more maintainable.
  • Multiple Inheritance: Interface used to achieve multiple inheritance and abstraction.
  • Define architecture: Interfaces add a plug and play like architecture into applications.
  • Modularity: Promote a cleaner and more modular design. By separating the definition of behavior from the implementation

Next Article
C# Interface

M

Mithun Kumar
Improve
Article Tags :
  • Misc
  • C#
  • CSharp-Interfaces
Practice Tags :
  • Misc

Similar Reads

    C# | Type.GetInterface() Method
    Type.GetInterface() Method is used to gets a specific interface implemented or inherited by the current Type. GetInterface(String) Method This method is used to search for the interface with the specified name. Syntax: public Type GetInterface (string name); Here, it takes the string containing the
    4 min read
    C# | Inheritance in interfaces
    C# allows the user to inherit one interface into another interface. When a class implements the inherited interface then it must provide the implementation of all the members that are defined within the interface inheritance chain.Important Points: If a class implements an interface, then it is nece
    3 min read
    C# | Type.GetInterfaces() Method
    Type.GetInterfaces() Method is used to get all the interfaces implemented or inherited by the current Type when overridden in a derived class. Syntax: public abstract Type[] GetInterfaces ();Return Value: This method returns an array of Type objects representing all the interfaces implemented or inh
    2 min read
    C# | How to use Interface References
    In C#, you are allowed to create a reference variable of an interface type or in other words, you are allowed to create an interface reference variable. Such kind of variable can refer to any object that implements its interface. An interface reference variable only knows that methods which are decl
    5 min read
    Default Interface Methods in C# 8.0
    Before C# 8.0 interfaces only contain the declaration of the members(methods, properties, events, and indexers), but from C# 8.0 it is allowed to add members as well as their implementation to the interface. Now you are allowed to add a method with their implementation to the interface without break
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences