- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Interface in C#
Interfaces define properties, methods, and events, which are the members of the interface. Interfaces contain only the declaration of the members. It is the responsibility of the deriving class to define the members. It often helps in providing a standard structure that the deriving classes would follow.
Let us see how to declare interface in C# with interface members −
public interface ITransactions { // interface members void showTransaction(); double getAmount(); }
The following is an example showing how to use Interface in C# −
Example
using System.Collections.Generic; using System.Linq; using System.Text; using System; namespace Demo { public interface ITransactions { // interface members void showTransaction(); } public class Transaction : ITransactions { private string tCode; private string date; public Transaction() { tCode = " "; date = " "; } public Transaction(string c, string d) { tCode = c; date = d; } public void showTransaction() { Console.WriteLine("Transaction ID: {0}", tCode); Console.WriteLine("Date: {0}", date); } } class Tester { static void Main(string[] args) { Transaction t1 = new Transaction("8877", "6/25/2018"); Transaction t2 = new Transaction("5656", "7/25/2018"); t1.showTransaction(); t2.showTransaction(); Console.ReadKey(); } } }
Output
Transaction ID: 8877 Date: 6/25/2018 Transaction ID: 5656 Date: 7/25/2018
- Related Articles
- Queue Interface In C#
- SortedMap Interface in C#
- C# Interface Types
- What is an interface in C#?
- How do you declare an interface in C++?
- Difference between Abstract Class and Interface in C#
- Difference between IComparable and IComparer Interface in C#
- Difference between IEnumerator and IEnumerable Interface in C#
- How to declare member function in C# interface?
- What does the interface ICollection do in C#
- What does the interface IEnumerable do in C#?
- What does the interface IList do in C#?
- What does the interface ICloneable do in C#?
- What does the interface IStructuralComparable do in C#?
- What does the interface IStructuralEquatable do in C#?

Advertisements