Good day, i am pretty new to how delegates work and require some assistance here is my code so far this is code in my main class.
using System;
using System.Collections.Generic;
using System.Linq;
namespace PROG6211_Taks_1_Tarisai_Gonah_18028480
{
class Program
{
public void notify(double exp)
{
Calculate cal1 = new Calculate();
cal1.totalExpenses = cal1.totalExpense + (cal1.carpayMonth + cal1.repayMonth);
if ((cal1.totalExpenses / cal1.grossIncome) * 100 > 75)
{
Console.WriteLine("Your expenses exceed 75% of gross Income");
}
}
static void Main(string[] args)
{
Calculate cal2 = new Calculate();
cal2.expenses = new cal2.expenses(notify);
var mydelegate = new expenses(cal2.notify);
In my main class i am trying to call trying to make the delegate run but im am struggling with that i am failing to create a method for it. here is my other class:
public delegate void expenses(double totalExpenses);
public void notify(expenses TotalExpenses)
{
TotalExpenses(0);
totalExpenses = totalExpense + (carpayMonth + repayMonth);
if ((totalExpenses / grossIncome) * 100 > 75)
{
Console.WriteLine("Your expenses exceed 75% of gross Income");
}
So I have created a method that does the function I require I did not show the full code because it's too much code but I have no issue with that, my problem is making the delegate in my other class run in my main method.
ive tried using this structure:
MyClass myClass = new MyClass();
MyClass.delgatename object = new MyClass.delegatename(method);
myClass.methodinotherclass(object);
this is the best i can to describe my problem hope you understand :)