Interface in C #
The interface in C # is defined as a syntactical contract that all Interface inheritance classes should follow. The interface defines the " What " section of the contract and the derived classes define the " How " section of the contract.
Interface defines attributes, methods and events, which are members of that Interface. The Interface contains only declarations of these members. Defining members is the responsibility of the derived class. It often helps provide a standard Structure that derived classes should follow.
The abstract classes to some extent usually serve the same purpose, however, they are mainly used when there are only a few methods declared by the base class and the derived class implements function.
Declaring Interface in C #
To declare the Interface in C # we use the interface
keyword. It is similar to class declaration. By default, the Interface command is public. This is the Interface declaration example in C #:
public interface GiaoDich { //các thành viên của interface void xemGiaoDich (); double laySoLuong (); }
For example:
The following example will illustrate the Interface implementation above:
using System . Collections . Generic ; using System . Linq ; using System . Text ; using System ; namespace GiaoDienUngDung { public interface QTM GiaoDich { //các thành viên của interface void xemGiaoDich (); double laySoLuong (); } public class GiaoDich : QTMGiaoDich { private string ma_giao_dich ; private string ngay_giao_dich ; private double so_luong ; //Lớp GiaoDich kế thừa từ QTMGiaoDich public GiaoDich () { ma_giao_dich = " " ; ngay_giao_dich = " " ; so_luong = 0.0 ; } public GiaoDich ( string c , string d , double a ) { ma_giao_dich = c ; ngay_giao_dich = d ; so_luong = a ; } public double laySoLuong () { return so_luong ; } public void xemGiaoDich () { Console . WriteLine ( "Giao dịch: {0}" , ma_giao_dich ); Console . WriteLine ( "Ngày giao dịch: {0}" , ngay_giao_dich ); Console . WriteLine ( "Số lượng: {0}" , laySoLuong ()); } } class Tester { static void Main ( string [] args ) { GiaoDich so 1 = new GiaoDich ( "001" , "08/06/2018" , 789000.00 ); GiaoDich so2 = new GiaoDich ( "002" , "09/06/2018" , 4519000.00 ); so1 . xemGiaoDich (); so2 . xemGiaoDich (); Console . ReadKey (); } } }
Running the above code we get the following result:
Transaction: 001
Transaction date: 08/06/2018
Quantity: 789000
Transaction: 002
Transaction date: 09/06/2018
Quantity: 4519000
According to Tutorialspoint
Previous article: Operator overloading in C #
Next lesson: Namespace in C #
You should read it
- Return to Windows 7 interface from Windows 8
- Experience Google 's new Gmail interface quickly
- Messenger returns to the old interface after only a few hours of testing the new interface
- Microsoft has revealed the new Windows 10 interface, inviting you to view and comment
- Facebook will have a completely new interface for Vietnamese users
- Google will death the old Gmail interface, forcing users to use the new interface
- How to put the Inbox interface into Gmail
- How to simplify the Facebook interface on Chrome
May be interested
- 21 Gmail tips on the new interface you should knowif you have updated the new and experienced gmail interface, the gmail tips on the new interface below will be extremely helpful.
- Experience the Material Design 2 interface for Chrome, you can activate itwith the material design 2 interface, google chrome browser will get a completely different interface with the main blue, sharp and sharp lines on the menu bar, browser tabs replaced by the interface round and round corners.
- Spotify has a new home screen interface, making it easy for users to find their favorite contentthe new home screen interface has begun to be available from today.
- YouTube on Android uses Material interfaceaccording to phonearena, the material interface is a type of design that google applies to the android 5.0 platform (first introduced by google in june), with the highlight being to use a flat and intuitive interface. this interface is directed by google for consistency among users of different android devices.
- Google Drive refines the user interface, making viewing folders easierrecently, google has just announced they are going to redo the user interface in the folder that users are shared with on google drive.
- The interface of Messenger messages is converted to a square and this is a fixrecently messenger's messaging interface on many facebook users' computers has been switched from rounded to square, causing discomfort when used. this may be just a temporary error of facebook, not a change in the look of this social network.
- iCloud interface changes iOS 7 styleapple has officially converted the entire interface of icloud service, with design and style bearing the stamp of ios 7.
- Outlook starts updating the dark interface (Dark mode) to users and this is how to activate itmicrosoft has just released a major change that allows users to use outlook.com's new (beta) interface to convert the interface to dark mode.
- How to compact the Gmail interface with Simplify Gmailthe simplify gmail utility will streamline the gmail interface, hiding content that is not needed.
- Here it is! New interface of Microsoft Officemicrosoft started testing the new user interface for office a few months ago. design elements as well as aesthetics in the new interface have generally been more in line with the style of windows 11.