using System; namespace CSharpInterfaceDemo { /***************************************** INTERFACE *****************************************/ // Define the interface // Note: An interface contains only the signatures of methods, delegates or events. //The implementation of the methods is done in the class that implements the interface interface IClient { void Order(int orderNum); string name { get; set; } string address { get; set; } } /**************************** CLASS THAT IMPLEMENTS THE INTERFACE ****************************/ // Create a Customer class that implements the IClient interface //The class must implement all the method(s) defined in the interface public class Customer : IClient { public string name { get; set; } public string address { get; set; } public Customer(string s) { Console.WriteLine("Creating a New Customer ID: {0}", s); } // Implement the Order method (mandatory) public void Order(int newOrder) { Console.WriteLine( "Implementing the Order Method for IClient. The Order Number is: {0}", newOrder); } } /**************************** USE THE CLASS ****************************/ class Program { public void Run() { //Initialize a new Customer instance Customer customer = new Customer("H56388"); //set the customer's name customer.name = "Brian Ferry"; //set the customer's address customer.address = "23 Orange Lane, Clifton, Bristol, BS6 5FH"; //Display the customer's name Console.WriteLine("The Name of the Customer is: {0}", customer.name); //Display the customer's address Console.WriteLine("The Address of the Customer is: {0}", customer.address); //Call the method "Order" with parameter 1234 customer.Order(1234); } static void Main() { //This block is executed when the application is started //Initialize an instance of "Program" class Program t = new Program(); //Call the method "Run". The block inside "run" will be executed t.Run(); Console.ReadLine(); } } }