0% found this document useful (0 votes)
50 views1 page

C# Single Cast Delegates Example

The document is a C# program that demonstrates the use of single-cast delegates for performing basic arithmetic operations such as addition, subtraction, multiplication, and division. It defines a delegate type 'Calculation' and implements methods for each arithmetic operation. In the 'Main' method, it creates a delegate instance, adds and removes methods, and invokes the delegate with two numbers.

Uploaded by

Madhuri Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views1 page

C# Single Cast Delegates Example

The document is a C# program that demonstrates the use of single-cast delegates for performing basic arithmetic operations such as addition, subtraction, multiplication, and division. It defines a delegate type 'Calculation' and implements methods for each arithmetic operation. In the 'Main' method, it creates a delegate instance, adds and removes methods, and invokes the delegate with two numbers.

Uploaded by

Madhuri Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SINGLE_CAST_DELEGATES
{
public delegate void Calculation(int num1, int num2);

class Program
{

public static void Addition(int num1, int num2)


{
int result = num1 + num2;
Console.WriteLine("Addition result is: {0}", result);
}
public static void Subtraction(int num1, int num2)
{
int result = num1 - num2;
Console.WriteLine("Subtraction result is: {0}", result);
}
public static void Multiplication(int num1, int num2)
{
int result = num1 * num2;
Console.WriteLine("Multiplication result is: {0}", result);
}
public static void Division(int num1, int num2)
{
int result = num1 / num2;
Console.WriteLine("Division result is: {0}", result);
}

static void Main(string[] args)


{
Calculation obj = new Calculation(Addition);
obj += Subtraction;
obj += Multiplication;
obj -= Division;
obj(150, 100);
Console.ReadLine();
}
}
}

You might also like