Program for Operator Overloading using C Sharp

using System;

class TSS

{

    int fees;

    public TSS()

    {

        fees=0;

    }

    public TSS(int f)

    {

        this.fees=f;

    }

    public static TSS operator+(TSS obj1, TSS obj2)

    {

        TSS obj = new TSS();

        obj.fees=obj1.fees + obj2.fees;

        return obj;

    }

    public void TotalFeeCollection()

    {

        Console.WriteLine(“Total Fee Collected ” +fees);

    }

   public static void Main()

    {

        TSS shubham = new TSS(10000);

        TSS gagan = new TSS(15000);

        TSS nadar = new TSS();

        nadar =shubham +gagan;

        nadar.TotalFeeCollection();

    }

}

Output: Total Fee Collected 25000

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.