Transaction: 001 Date: 24/06/2014 amnt: 87900 Transaction: 002 Date: 25/06/2014 amnt: 51900
Users Online
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Latest Articles
Articles Hierarchy
C# Program to Demonstrate Transactions using Interface
C# Program to Demonstrate Transactions using Interface
This is a C# Program to demonstrate transactions using interface.
This C# Program Demonstrates Transactions using Interface.
Here interfaces define properties, methods and events, which are the members of the interface and contains only the declaration of the members and has the responsibility of the deriving class to define the members.
Here is source code of the C# Program to Demonstrate Transactions using Interface. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Demonstrate Transactions using Interface */ using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace sample { public interface ITransactions { void showTransaction(); double getamnt(); } public class Transaction : ITransactions { private string Code; private string date; private double amnt; public Transaction() { Code = " "; date = " "; amnt = 0.0; } public Transaction(string c, string d, double a) { Code = c; date = d; amnt = a; } public double getamnt() { return amnt; } public void showTransaction() { Console.WriteLine("Transaction: {0}", Code); Console.WriteLine("Date: {0}", date); Console.WriteLine("amnt: {0}", getamnt()); } } class example { static void Main(string[] args) { Transaction t1 = new Transaction("001", "24/06/2014", 87900.00); Transaction t2 = new Transaction("002", "25/06/2014", 51900.00); t1.showTransaction(); t2.showTransaction(); Console.ReadKey(); } } }
This C# we are creating two object variables t1 and t2 for Transaction class. The showTransaction() and getamt() functions are defined as ITransactions Interface.
Hence interfaces define properties, methods, and events, which are the members of the interface. Interfaces contain only the declaration of the members and 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.