CSharp form application 5


CSharp form application 5

>




In CSharp form application 5, we will delve through the concept of abstract class in form application.
Abstract classes are nearly identified with interfaces. They are classes that can’t be instantiated, and are often either not mostly implemented (as opposed to interfaces), or not in any manner being implemented. One key distinction between abstract classes and interfaces is that a class may implement a boundless number of interfaces, yet may acquire from a single(abstract or other type of) class. A class that is gotten from this class may implement interfaces. Abstract classes are helpful when making components because they allow us not to implement some methods inside them.

We will now design a simple form application that will show some functionalities of using the Abstract classes.
Design a simple from with six label controls over it. The three labels have no text:

Abstract Class

Now , we shall write some code to implement the functionality of our application:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Abstract_Classes
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

int sub = absbaseClass.Subtraction(4,1);
lbl4minus1.Text = sub.ToString();

absDerived derivedClass = new absDerived();
int add = derivedClass.Addition(2,2);
lbl2plus2.Text = add.ToString();

int mul = derivedClass.Multiplication(5,2);
lbl5into2.Text = mul.ToString();

}

//base abstract class
abstract class absbaseClass
{

// abstract methods
public abstract int Addition(int a, int b);
public abstract int Multiplication(int c, int d);

// non abstract method
public static int Subtraction(int e, int f)
{
return e-f;
}

}

//derived abstract class
abstract class absderivedClass : absbaseClass
{

public override int Addition(int Number1, int Number2)
{
return Number1 + Number2;
}
}

class absDerived : absderivedClass
{

public override int Multiplication(int Number1, int Number2)
{
return Number1 * Number2;
}
}

}
}

Now , execute the application and see the result:

abstract class2

Syed Adeel Ahmed
Analyst, Programmer, Educationist and Blogger at Technofranchise
Computer Systems Engineer from Sir Syed University Of Engineering & Technology.I am passionate about all types of programming.
Syed Adeel Ahmed on FacebookSyed Adeel Ahmed on GoogleSyed Adeel Ahmed on InstagramSyed Adeel Ahmed on Twitter

Published by

Syed Adeel Ahmed

Computer Systems Engineer from Sir Syed University Of Engineering & Technology.I am passionate about all types of programming.

Leave a Reply