This article shows how to create a new class and call its member functions from Main progrmam. CalCulator is a class which has some member functions such as Square, Add, Subtract, Multiply etc. using System;// Creating a simple Calculator class/// <summary>/// Summary description for Class1./// </summary>public class CalCulator{// Square function public int Square(int num){return num*num;}// Add two integers and returns the sumpublic int Add(int num1, int num2 ){return num1 + num2;}// Add two integers and returns the sumpublic double Add(double num1, double num2 ){return num1 + num2;}// Multiply two integers and retuns the resultpublic int Multiply(int num1, int num2 ){return num1 * num2;}// Subtracts small number from big numberpublic int Subtract(int num1, int num2 ){if ( num1 > num2 ){return num1 - num2;}return num2 - num1;}}// This shows how to use CalCulator class from Main C# program.public class Class1{static void Main() {CalCulator sq = new CalCulator();Console.WriteLine( sq.Square(8).ToString());Console.WriteLine( sq.Add(8.3, 9.24).ToString());Console.WriteLine( sq.Multiply(5,8).ToString());Console.WriteLine( sq.Subtract(22, 42).ToString());}}Build and run the application.
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: