C# Program to Demonstrate Transactions using Interface

This is a C# Program to demonstrate transactions using interface.

Problem Description

This C# Program Demonstrates Transactions using Interface.

Problem Solution

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.

Program/Source Code

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();
        }
    }
}
Program Explanation

This C# we are creating two object variables t1 and t2 for Transaction class. The showTransaction() and getamt() functions are defined as ITransactions Interface.

advertisement

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.

Runtime Test Cases
 
Transaction: 001
Date: 24/06/2014
amnt: 87900
Transaction: 002
Date: 25/06/2014
amnt: 51900

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

🎓 Free Certifications on 300 subjects are live for December 2025. Register Now!
If you wish to look at all C# Programming examples, go to 1000 C# Programs.

advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
I’m Manish - Founder and CTO at Sanfoundry. I’ve been working in tech for over 25 years, with deep focus on Linux kernel, SAN technologies, Advanced C, Full Stack and Scalable website designs.

You can connect with me on LinkedIn, watch my Youtube Masterclasses, or join my Telegram tech discussions.

If you’re in your 20s–40s and exploring new directions in your career, I also offer mentoring. Learn more here.