0% found this document useful (0 votes)
6 views7 pages

Lab10 Programs

The document contains code examples demonstrating the use of interfaces and delegates in C#. It includes two implementation classes that showcase method implementations for addition and subtraction, as well as a delegate for banking operations. Additionally, it suggests enhancements for the banking program, such as adding withdrawal functionality and simulating a calculator application.

Uploaded by

Shashank S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views7 pages

Lab10 Programs

The document contains code examples demonstrating the use of interfaces and delegates in C#. It includes two implementation classes that showcase method implementations for addition and subtraction, as well as a delegate for banking operations. Additionally, it suggests enhancements for the banking program, such as adding withdrawal functionality and simulating a calculator application.

Uploaded by

Shashank S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Lab10 Programs

Demonstration using Interfaces


using System;
namespace AbstractClassMethods
{
class Program
{
static void Main()
{
ImplementationClass1 obj1 = new ImplementationClass1();
//Using obj1 we can only call Add method
obj1.Add(10, 20);
//We cannot call Sub method
//obj1.Sub(100, 20);
• ImplementationClass2 obj2 = new
ImplementationClass2();
• //Using obj2 we can call both Add and
Sub method
• obj2.Add(10, 20);
• obj2.Sub(100, 20);
• Console.ReadKey();
• }
• interface ITestInterface1
• {
• void Add(int num1, int num2);
• }
• interface ITestInterface2 : ITestInterface1
• {
• void Sub(int num1, int num2);
• }
• public class ImplementationClass1 : ITestInterface1
• {
• //Implement only the Add method
• public void Add(int num1, int num2)
• {
• Console.WriteLine($"Sum of {num1} and {num2} is {num1 + num2}");
• }
• }
• public class ImplementationClass2 : ITestInterface2
• {
• //Implement Both Add and Sub method
• public void Add(int num1, int num2)
• {
• Console.WriteLine($"Sum of {num1} and {num2}
is {num1 + num2}");
• }
• public void Sub(int num1, int num2)
• {
• Console.WriteLine($"Divison of {num1} and
{num2} is {num1 - num2}");
• }
• }
•}
• Demonstration on Delegates
• using System;
• using System.Security.Cryptography.X509Certificates;
• namespace DelegateAddon
• {
• class Dele
• { int Bal =5000;
• public delegate void Bank_Del(); // Delegate Declaration
• public void Bank()
• {
• Console.WriteLine("Enter your choice to deposit or withdraw 1 or 2");
• int i = int.Parse(Console.ReadLine());
• if (i == 1)
• {
• Console.WriteLine("Enter the amount to be deposited");
• int dep = int.Parse(Console.ReadLine());
• Console.WriteLine("Your current Balance is {0}", Bal + dep);

• }
• }
• public static void Main(string[] args)
• {
• Dele D = new Dele();// Class Instatiation
• Bank_Del BD = new Bank_Del(D.Bank);// Delegate
Instantiation
• BD(); // Delegate Invocation

• }
• }
• }
• Addon1:
• Complete the above program by adding the code for Withdrawal.
• Addon2
• Rewrite the above program by sending Balance as a function parameter.
Windows Application: Follow the
manual
• Addon Simulate the caliculator

You might also like